How can we write query in mongodb which is equals to the inner select sql query.
select field1, field2
from workflowTable
where id in(select idField from usersTable)
No of hits to the db should be same.
Let's think you have 3 documents.collection name is users.
{
"_id": ObjectId("4efa8d2b7d284dad101e4bc9"),
"Last Name": "DUMONT",
"First Name": "Jean",
"alert":1,
"Date of Birth": "01-22-1963"
},
{
"_id": ObjectId("4efa8d2b7d284dad101e4bc7"),
"Last Name": "PELLERIN",
"First Name": "Franck",
"alert":2,
"Date of Birth": "09-19-1983",
"Address": "1 chemin des Loges",
"City": "VERSAILLES"
},
{
"_id": ObjectId("4efa8d2b7d284dad101e4bc7"),
"Last Name": "PELLERIN",
"First Name": "Franck",
"alert":3,
"Date of Birth": "09-19-1983",
"Address": {
"Street": "1 chemin des Loges",
"City": "VERSAILLES"
}
}
In above document i want only 2 document which column contain alert 1 and 2.Query for that
db.users.find({alert:{$in:[1,2]}})
This will give me first two document.
You can use $in parameter in mongodb for this query. Check this tutorial for more information.