Filtering Flashcards
Mongo DB:
Select records from collection where field1 equals value
db.collection.find({field1: value})
MongoDB
Select records from collection where field1 greater than value
db.collection.find({field1: {$gt: value}})
MongoDB
Select records from collection where field1 lower than value
db.collection.find({field1: {$lt: value}})
Mongo DB
Select records from collection where field1 lower than or equal to value
db.collection.find({field1: {$lte: value}})
Mongo DB
Select records from collection where field1 greater than or equal to value
db.collection.find({field1: {$gte: value}})
Mongo DB
Select records from collection using and condition
db.collection.find($and: [{condition1}, {condition2}])
Mongo DB
Select records from collection using regex
db.collection.find({field: {$regex: “pattern”}})
Mongo DB
Select records from collection which have a given size
db.collection.find({field: {$size: value}})
Mongo DB
Select records from collection which have a given field
db.collection.find({field: {$exists: true}})
Mongo DB
Select records from collection which don’t have a given field
db.collection.find({field: {$exists: false}})
Mongo DB
Select records from collection sorted by a given field ascending
db.collection.find().sort({field: 1})
Mongo DB
Select records from collection sorted by a given field descending
db.collection.find().sort({field: -1})
Mongo DB
Select records from collection limited by a given amount
db.collection.find().limit(limitCount)
Mongo DB
Select records from collection skiped by a given amount
db.collection.find().skip(skipCount)
Mongo DB
Select records from collection including specific fields only
db.collection.find({}, {field1: 1, fields2: 1})