在猫鼬中查找不同的文档

时间:2014-01-26 05:03:01

标签: node.js mongodb mongoose

考虑一下这样的集合:

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

知道我想要检索条件,其中='jhony'和status ='yes'没有任何重复(重复)。

输出应该是

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

如何在节点js中使用mongoose实现它。

我试过这个

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

然后我得到错误:

          No value for 'distinct' has been declared.

1 个答案:

答案 0 :(得分:0)

听起来我想要使用findOne

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