Mongodb query based on item at specific position in array

旧时模样 提交于 2019-12-17 14:57:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!