Skip to content Skip to sidebar Skip to footer

Running Multiple Queries In Mongo`

I have a collection and want to get a set of results that met a set of conditions. I understand the Mongo doesn't let you use joins so I would need to run separate queries and join

Solution 1:

In your specific example, you do not need to run those queries separately. You can join the results like so:

coll.find(
  { $or : [ 
      { "coordinates.type" : "Point" }, 
      { "place.bounding_box.type" : "Polygon" } 
    ] 
  },
  {"coordinates" :1, "place.bounding_box.coordinates" : 1}
)

You can also use $and / $elementMatch instead of an $or

Post a Comment for "Running Multiple Queries In Mongo`"