【问题标题】:Meteor Multiple Field Find流星多场查找
【发布时间】:2016-05-16 05:17:47
【问题描述】:

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

我正在尝试通过集合查找并使用多个值进行过滤。

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

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

【问题讨论】:

  • 你希望这个表达式做什么?您是否阅读了find 上的文档?第二个参数应该是什么?

标签: meteor collections find


【解决方案1】:
  1. .find() 的第一个参数是查询。
  2. $or 将对象矩阵作为值
  3. Meteor.user()._id 可以缩写为 Meteor.userId()

例如:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多