2

I am very much a beginner in NoSQL. can someone help me with the query that would find all of the documents that are "Point" geojson types in my collection?

Here is an example document:

    {
    "_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"
        }
    ]
}

and in Robomongo visual:

Robomongo screenshot of document

I am getting lost because of the array (entities) of objects (0) which have objects (geoJson) which have elements (type). I have read the following and while they the answers on them make sense to me, I can't seem to fix my confusion on my example.

Mongo db - Querying nested array and objects

Querying an array of arrays in MongoDB

What query do I need and can you elaborate the explanation of each level?

Just to be clear the entities array can have any number of objects so the query needs to check all objects in that array, not just "0" as i nthe example image below:

Example with multiple objects in the array

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
DMusketeer
  • 133
  • 7

1 Answers1

1

The query will be as simple as:

db.collection.find({"entities.geoJson.type": "Point"});
Oleks
  • 1,633
  • 1
  • 18
  • 22
  • Thank you, this worked perfectly. I think I was over complicating it.... I'll mark as the answer soon. I have to wait 9 minutes apparently. – DMusketeer Jan 23 '17 at 16:48