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 }
}
}
])