3

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 Answer 1

8

Change your query to the following

   db.users.find({"location.coordinates.0" : -73.04303})
Sign up to request clarification or add additional context in comments.

1 Comment

What id the index is a variable, not 0?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.