2014-01-26 71 views
-1

不同的文件讓我們考慮這樣一個集合:爲了找到貓鼬

{"to": 'jhony', "satus": 'no' } 
    {"to": 'jhony', "satus": 'yes' } 
    {"to": 'king', "satus": 'yes' } 
    {"to": 'jhony', "satus": 'yes' } 

知道我要到哪裏=「jhony」和狀態=「是」沒有任何重複(重複)檢索與條件。

即輸出應該

  {"to": 'jhony', "satus": 'yes' } 

我如何在節點JS用貓鼬實現它。

我試過這樣

 Chat.find().distinct({ to: { $in: [ now ] }, status: { $in: [ sot ] } }, function(err, docs){ 

然後我得到了錯誤的:像你想使用

  No value for 'distinct' has been declared. 

回答

0

的聲音,我findOne

Chat.findOne({ to: 'jhony', satus: 'yes' }, function(err, result) { 
    ... 
});