2013-05-19 1 views
0

이 트윗의 .json 데이터를 제공하는 컬렉션이를 ... MongoDB를은()을 찾아 (계산) - 구문 에러 :. 실종 : 속성 ID (쉘) 후 : 1

이 세션에서 삭제-요청을 계산하는 상대 :

db.tweets.find({"delete"}).count() 

그리고 SyntaxError: missing : after property id (shell):1

수행에 더 많은 find()count() 작업을해야하기 때문에이 구문이 올바르지 않습니다,하지만 오류가 일치한다. ("은 ..."는 문자 및/또는 숫자의 시리즈 중 하나입니다)

은 삭제-요청이 모습입니다 다음 find() 기능에

{ 
    "_id" : ObjectId("…"), 
    "delete" : { 
     "status" : { 
      "id" : NumberLong("…"), 
      "user_id" : …, 
      "id_str" : "…", 
      "user_id_str" : "…" 
     } 
    } 
} 

답변

5

당신은을 통과해야 목적. {"delete"}은 유효한 개체가 아니기 때문에 키/값을 놓쳤습니다.

삭제 키가있는 문서의 수를 얻고 싶다고 생각합니다. 이를 위해서는 true 값을 가진 $exists 연산자를 사용해야합니다.

db.tweets.find({ "delete": { $exists: true } }).count(); 

또는 documentation에서 직접

db.tweets.count({ "delete": { $exists: true } }); 

:

$exists selects the documents that contain the field if is true. If is false, the query only returns the documents that do not contain the field. Documents that contain the field but has the value null are not returned.

+0

적합합니다. 건배, 그리고 고마워 .. – sourcingsynergy