【问题标题】:To find distinct document in mongoose在猫鼬中查找不同的文档
【发布时间】:2014-02-17 01:20:05
【问题描述】:

让我们考虑这样的集合:

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

知道我想检索条件 where to = 'jhony' 和 status = 'yes' 没有任何重复(重复)。

即输出应该是

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

如何在 node js 中使用 mongoose 来实现它。

我试过这样

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

然后我得到错误:

          No value for 'distinct' has been declared.

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

    听起来你想使用findOne

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

    【讨论】:

      猜你喜欢
      • 2014-02-03
      • 1970-01-01
      • 2017-10-05
      • 2016-11-02
      • 2014-01-26
      • 2013-10-05
      • 2022-01-17
      • 2015-06-26
      • 2019-10-19
      相关资源
      最近更新 更多