R
R
Ravenswood2021-06-09 15:35:50
Python
Ravenswood, 2021-06-09 15:35:50

How to get all records with the same city in MongoDB?

Hello! How do I get all records with the same city. I have this:

{"_id":"1", "city": "London", "number": "11"}
{"_id":"2", "city": "Paris", "number": "31","}
{"_id":"3", "city": "Moscow", "number": "1"}
{"_id":"4", "city": "Kiev", "number": "131"}
{"_id":"5", "city": "London", "number": "551}
{"_id":"7", "city": "London", "number": "11"}
{"_id":"8", "city": "London", "number": "44"}
{"_id":"9", "city": "Paris", "number": "177"}
{"_id":"10", "city": "Kiev", "number": "77",}


I want to get where the city of London is, i.e.:
{"_id":"1", "city": "London", "number": "11"}
{"_id":"5", "city": "London", "number": "551}
{"_id":"7", "city": "London", "number": "11"}
{"_id":"8", "city": "London", "number": "44"}


How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
McBernar, 2021-06-09
@Ravenswood

const query = {
  city: 'london'
}
collection.find(query).toArray()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question