2013-07-22 8 views
0

속성 :MongoDB의 쿼리를 사용하여 .attrs 나는 다음과 같은 JSON을 감안할 때

{ 
    "A" : {...}, 

    ".attrs" : {"A1": "1" } 
} 

내가 A.attrs 필드 값을 쿼리 드릴 수 없습니다 R.에서 패키지를 rmongodb 사용하여 쿼리 싶습니다. 어떤 제안?

mongo <- mongo.create() 
if (mongo.is.connected(mongo)) { 
    buf <- mongo.bson.buffer.create() 
    mongo.bson.buffer.append(buf, "A.attrs", "1") 
    query <- mongo.bson.from.buffer(buf) 

    # assume "db.collection" is correct 
    cursor <- mongo.find(mongo, "db.collection", query, limit=1000L) 
    # Step though the matching records and display them 
    while (mongo.cursor.next(cursor)) 
    print(mongo.cursor.value(cursor)) 
    mongo.cursor.destroy(cursor) 
} 

(.)은 Mongo의 유효한 필드 이름이 아니지만, 그것은 json 변환기에 XML을 사용하여 생성되었습니다.

"\ uff0E"는 이스케이프 문자로 도움이되지 않았습니다. .attrs의 이름을 유효한 규칙으로 바꾸는 것이 가장 좋지만 json의 다양한 중첩 수준에 여러 개의 .attrs가 있습니다.

답변

2

키 기간이 문제입니다. 좋은 것으로 가정하면 다음과 같이 검색어를 구성해야합니다.

mongo.bson.buffer.append(buf, ".attrs.A1", "1")