流星多场查找

时间:2016-02-06 05:03:26

标签: meteor collections find

可能是一个简单的解决方法,我查看了Meteor文档并找不到答案。

我正在尝试使用多个值来查找集合和过滤器。

在应用程序中,每个对话中有2个人。我需要找出两个人之间是否已经存在对话。

var convoexists =  Convo.find({
          $or: [{user_1: Meteor.user()._id},{user_2: userid}]
     }, { 
          $or: [{user_1: userid,{user_2: Meteor.user()._id}}]
     });

1 个答案:

答案 0 :(得分:1)

  1. .find()的第一个参数是查询。
  2. $or将对象矩阵作为值
  3. Meteor.user()._id可缩短为Meteor.userId()
  4. 例如:

    var convoexists =  Convo.find({
      $or: [
        { user_1: Meteor.userId(), user_2: userid },
        { user_1: userid, user_2: Meteor.userId() }
      ]
     });