Minimongo目前尚不支持$运算符 [英] Minimongo doesn't support $ operator in projections yet

查看:70
本文介绍了Minimongo目前尚不支持$运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这份文件:

...
    "username" : "torayeff",
    "profile" : {
        ...
        "friends" : [
            {
                "_id" : "aSD4wmMEsFnYLcvmP",
                "state" : "active"
            },
            {
                "_id" : "ShFTXxuQLAxWCh4cq",
                "state" : "active"
            },
            {
                "_id" : "EQjoKMNBey7WPGamC",
                "state" : "new-request"
            }
        ]
        ...
    }
...

这是仅获取给定用户的州" 属性的查询:

This is query for getting only "state" attribute of given user:

Meteor.users.findOne({_id: userId1, 'profile.friends._id': userId2}, 
                    {fields: {_id: 0, 'profile.friends.state.$':1} });

在流星中,我收到此错误:

In meteor I am receiving this error:

Exception while simulating the effect of invoking 'activateFriendship' Error: Minimongo doesn't support $ operator in projections yet...

如何在minimongo中没有错误的情况下重写以上查询?

How can I rewrite above query without having error in minimongo?

推荐答案

您可以喜欢

如果您只想获取没有键的值,请使用此

EDIT : if you just want to grab the values without keys, use this

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()

$不需要项目运营商

这篇关于Minimongo目前尚不支持$运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆