Querying MongoDB
2 ways to view the entire contents of collection
db.getCollection("friendsCollection").find()
db.friendsCollection.find()Filter Documents
// exact match
db.friendsCollection.find(
{
age: 31
}
)
// less than
db.friendsCollection.find(
{
age : {$lt : 31}
}
)
// greater than
db.friendsCollection.find(
{
age : {$gt : 30}
}
)
// Between
db.friendsCollection.find(
{
age : {$gt : 29},
age : {$lt : 31}
}
)
// nested
db.friendsCollection.find({"name.firstname":"Ben"});More Queries
Using Regular Expression
Regular expressions are used within two slashes / /
Last updated