【问题标题】:Fetching fields which have values as array in mongodb在mongodb中获取值作为数组的字段
【发布时间】:2015-08-25 19:06:52
【问题描述】:

我的收藏看起来有点像这样

{a:"foo", b:[10,20,30]}
{a:"boo", b:[15,25,35]}
{a:"abc", b:[10,40,50]}
{a:"xyz", b:[10,60,70]}

现在,我想检索 a:"foo" 下的整个数组。我该怎么做?

【问题讨论】:

    标签: node.js mongodb


    【解决方案1】:
    db.collection.find({"a":"foo"})
    

    将返回所有符合条件的对象,然后您可以访问结果的“b”元素

    【讨论】:

      【解决方案2】:

      试试这个:

       db.collection.find({"a":"foo"},{"b":1})
      

      它会返回 b 数组。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-07-16
        • 1970-01-01
        • 1970-01-01
        • 2016-06-12
        • 2022-12-16
        • 1970-01-01
        • 1970-01-01
        • 2020-03-02
        相关资源
        最近更新 更多