问题
I want to run a query where an item at a specific position in an array needs to be compared.
For example, consider the GeoJSON format for storing location data.
//sample document from collection user
{
name: "Some name",
location : {
type: "Point",
coordinates : [<Longitude>, <Latitude>]
}
}
How would I query users located at a specific longitude?
I cant seem to find anything in the documentation which can help me do the same.
Queries I have tried:
db.users.find({"location.coordinates[0]" : -73.04303})
回答1:
Change your query to the following
db.users.find({"location.coordinates.0" : -73.04303})
来源:https://stackoverflow.com/questions/28411416/mongodb-query-based-on-item-at-specific-position-in-array