Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb Minimongo不';我们还不支持$operator的预测_Mongodb_Meteor - Fatal编程技术网

Mongodb Minimongo不';我们还不支持$operator的预测

Mongodb Minimongo不';我们还不支持$operator的预测,mongodb,meteor,Mongodb,Meteor,我有以下文件: ... "username" : "torayeff", "profile" : { ... "friends" : [ { "_id" : "aSD4wmMEsFnYLcvmP", "state" : "active" }, { "_id" : "ShFTXxuQL

我有以下文件:

...
    "username" : "torayeff",
    "profile" : {
        ...
        "friends" : [
            {
                "_id" : "aSD4wmMEsFnYLcvmP",
                "state" : "active"
            },
            {
                "_id" : "ShFTXxuQLAxWCh4cq",
                "state" : "active"
            },
            {
                "_id" : "EQjoKMNBey7WPGamC",
                "state" : "new-request"
            }
        ]
        ...
    }
...
这是一个仅获取给定用户的“状态”属性的查询:

Meteor.users.findOne({_id: userId1, 'profile.friends._id': userId2}, 
                    {fields: {_id: 0, 'profile.friends.state.$':1} });
在meteor中,我收到以下错误:

Exception while simulating the effect of invoking 'activateFriendship' Error: Minimongo doesn't support $ operator in projections yet...
如何重写上述查询而不在minimongo中出错?

用于查找嵌套数组,并在投影中使用,因此查询如下:

Meteor.users.findOne({
  "_id": userId1,
  "profile.friends": {
    "$elemMatch": {
      "_id": userId2
    }
  }
}, {
  "profile.friends.state.$": 1
})
你可以像我一样

编辑:如果您只想获取没有键的值,请使用此选项

Meteor.users.distinct('profile.friends.state', {_id: userId1, 'profile.friends._id': userId2});
在一般情况下:

Meteor.users.findOne({_id: userId1, 'profile.friends._id': userId2}).select({ _id: 0, 'profile.friends.state':1 }).exec()

$
project operator not required

这将返回[“状态”:“活动”,“状态”:“活动”,“状态”:“新请求”],而我只需要1个元素,这就是我使用的原因。$这个答案忽略了一点:如何在数组中仅获取与查询匹配的一个完整对象。