MongoDB數據庫的查詢操作方法有以下幾種:
例:db.collection.find({ age: 25 })
例:db.collection.findOne({ age: 25 })
例:db.collection.count({ age: 25 })
例:db.collection.distinct(“name”, { age: 25 })
例:db.collection.findAndModify({
query: { age: 25 },
update: { $set: { name: “John” } },
new: true
})
例:db.collection.aggregate([
{
$group: {
_id: “$age”,
count: { $sum: 1 }
}
}
])