问题
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 the results into a single response.
But is it possible to join the results of separate queries together to get the intended output.
Are there any basic examples I could see query results joined together.
Thanks
For example could I join these two queries so I get the results of both queries:
coll.find({"coordinates.type" : "Point"},{"coordinates" :1}, tailable = True, timeout = False)
and:
coll.find({"place.bounding_box.type" : "Polygon"},{"place.bounding_box.coordinates" : 1}, tailable = True, timeout = False)
回答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
来源:https://stackoverflow.com/questions/13385986/running-multiple-queries-in-mongo