【问题标题】:How find specific value in array mongodb如何在数组 mongodb 中找到特定值
【发布时间】:2020-05-23 10:41:08
【问题描述】:

伙计们,我在 mongodb 4.2 中有这样的文档:

"DifferenceValue" : "[{\"PropertyName\":\"Id\",\"PropertyLabel\":\"\",\"CurrentValue\":2725,\"NextValue\":null},{\"PropertyName\":\"ClientIpAddress\",\"PropertyLabel\":\"\",\"CurrentValue\":\"192.168.1.203\",\"NextValue\":null},{\"PropertyName\":\"SessionId\",\"PropertyLabel\":\"\",\"CurrentValue\":\"b4sd54s6d4sr4\",\"NextValue\":null})}]"

如何在 mongodb 中找到具有 2725 值的 CurrentValue 键。 (对不起我的英语不好)

【问题讨论】:

  • 到目前为止你自己尝试过什么?
  • db.Audit.find({DifferenceValue : {CurrentValue : 7880174}}).pretty() @Huber
  • 你也可以添加,你的预期输出
  • 什么都不显示@PuneetSingh
  • 您想要查找 curretValues 并且想要 MongoDB 查询?因此,您希望输出哪种 JSON 格式,示例 JSON 输出可以更好地理解您的问题

标签: arrays mongodb mongodb-query pymongo document


【解决方案1】:

试试:

mongo 查询:

db.getCollection('collection_name').find({'CurrentValue':2725})

pymongo 查询:

  1. 连接到 Mongo
  2. 获取 pymongo.command_cursor.CommandCursor
  3. 那就试试吧-

    for i in collection.find({'CurrentValue':2725}): print(i) break

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多