【问题标题】:How can I add a Mongo Query inside one Document and insert it in a Collection?如何在一个文档中添加 Mongo 查询并将其插入到集合中?
【发布时间】:2017-04-03 11:27:08
【问题描述】:

这是一个示例文档。我希望在“条件”字段中插入一个 MongoDB 查询。

那么怎么插入呢?

{
    "_id": 9000001,
    "GeoId": 111002,
    "collection": "Age",
    "condition": "{ db.age.find({"Fields.FieldValue" : ""})}",
    "alertMessageTemplate": "The age is #<20#  & #>100# ",
}

【问题讨论】:

    标签: json mongodb mongodb-query


    【解决方案1】:

    我最好的方法是集合名称和条件是单独的字段:

    "collection": "Age",
    "condition": {"Fields.FieldValue" : ""},
    

    这样您可以将条件保存为 JSON 对象。

    然后你可以在 find 上格式化:db.getCollection('+collection+').find('+condition+');

    【讨论】:

    • 将尝试使用 Java 并检查我是否可以读取该查询。谢谢
    猜你喜欢
    • 2021-03-28
    • 1970-01-01
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    • 2015-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多