【问题标题】:Get documents with field that isn't a particular string获取字段不是特定字符串的文档
【发布时间】:2017-08-01 20:23:12
【问题描述】:

我想从 MongoDB 中获取 没有 字段 "name":"John" 的文档(只是一个示例)。

我该怎么做?

为了获取具有"name":"John" 字段的文档,我使用:

db.col.find({"name":"John"})

我已经尝试过...find(!{"name":"John"})

【问题讨论】:

    标签: node.js mongodb database


    【解决方案1】:
    db.col.find({"name":{$ne: "John"}})
    

    应该可以,这里有文档:Mongo, Advanced Queries.

    【讨论】:

      【解决方案2】:

      只需像这样使用$ne 选择器:

      db.col.find({"name":{$ne:"John"}})
      

      http://docs.mongodb.org/manual/reference/operator/ne/#_S_ne

      【讨论】:

        猜你喜欢
        • 2021-11-27
        • 1970-01-01
        • 2021-07-20
        • 2019-05-28
        • 2018-09-04
        • 2021-07-22
        • 1970-01-01
        • 1970-01-01
        • 2021-01-22
        相关资源
        最近更新 更多