【问题标题】:MongoDB: Querying layers of objects and arraysMongoDB:查询对象和数组的层
【发布时间】:2017-01-23 16:42:02
【问题描述】:

我是 NoSQL 的初学者。有人可以帮我查询一下,在我的集合中找到所有“Point”geojson 类型的文档吗?

这是一个示例文档:

    {
    "_id" : ObjectId("5886276637ccefbcc5c84db2"),
    "docId" : "10bc70fb2d709f7f51b6a2cae363c8f46786fb113bc6165fb0d45e24086197fd",
    "entities" : [ 
        {
            "geoJson" : {
                "type" : "Point",
                "coordinates" : [ 
                    "16.44184", 
                    "100.34879"
                ]
            },
            "isNormalised" : false,
            "confidence" : 1.0,
            "externalId" : "1ee5f6e691a43e0f34b65f9c95b4443dc9809c496d9c825f251c9883e4bf5e28",
            "end" : 2746,
            "subType" : null,
            "type" : "Location",
            "begin" : 2740,
            "value" : "Pichit"
        }
    ]
}

在 Robomongo 视觉中:

我迷路了,因为对象 (0) 的数组 (实体) 具有对象 (geoJson),而对象 (geoJson) 具有元素 (类型)。我已阅读以下内容,虽然它们的答案对我来说很有意义,但我似乎无法解决我对示例的困惑。

Mongo db - Querying nested array and objects

Querying an array of arrays in MongoDB

我需要什么查询,你能详细说明每个级别的解释吗?

为了清楚实体数组可以包含任意数量的对象,因此查询需要检查该数组中的所有对象,而不仅仅是下面示例图片中的“0”:

【问题讨论】:

    标签: mongodb mongodb-query


    【解决方案1】:

    查询将很简单:

    db.collection.find({"entities.geoJson.type": "Point"});
    

    【讨论】:

    • 谢谢您,这非常有效。我想我把它复杂化了......我很快就会标记为答案。我显然要等 9 分钟。
    猜你喜欢
    • 1970-01-01
    • 2021-09-24
    • 1970-01-01
    • 2012-07-23
    • 1970-01-01
    • 2012-05-05
    • 2014-05-13
    • 1970-01-01
    • 2021-01-09
    相关资源
    最近更新 更多