【问题标题】:How can I use in query in mongodb?如何在 mongodb 的查询中使用?
【发布时间】:2020-10-13 07:17:21
【问题描述】:

如果我的mongodb中的数据是这样的

{
    "category": "Pop Culture",
    "subcategory": "Film Directors",
    "name": "Quentin Tarantino",
}

有什么方法可以只使用名称的一部分找到这个对象

喜欢:

db.data.find_one({'name': 'quentin'})

【问题讨论】:

    标签: mongodb mongodb-query pymongo pymongo-3.x


    【解决方案1】:

    对于string数据,可以使用$regex操作符来查找部分字段数据。

    示例:

    db.collection.findOne({
      name: {
        $regex: "Some part of name"
      }
    })
    

    更多信息请参见$regex

    【讨论】:

      猜你喜欢
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-19
      • 2015-07-22
      相关资源
      最近更新 更多