M
M
mitaichik2015-04-11 19:34:18
MongoDB
mitaichik, 2015-04-11 19:34:18

How to make a request to mongo?

Hello! You need to make a request to mongo, I don’t understand how to do it:
First, about the structure of the document:
route.stations[].id
route - bus route object
stations - array of stations in the route.
id - unique identifier of the station, integer
You need to select a route that contains 2 stations at the same time. That is, in the array of stations there is both one and the other station at the same time.
I try like this:

db.Bus.find({
    "route.stations.id" : {$in : [1045,  7045]}
})

But it finds if any station is present. How to make sure that both are?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shikanov, 2015-04-11
@mitaichik

More or less like this:

db.Bus.find({
    $and: [
        {"route.stations.id": {$in : [1045]}},
        {"route.stations.id": {$in : [7045]}}
    ]
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question