标签:mongo res vga 标准 数组类 roo path bsp insert
db.集合名称.aggregate([{管道:{表达式}}])
ps ajx | grep mongo
表达式:‘$列名‘
db.stu.aggregate([
{$group:
{
_id:‘$gender‘,
counter:{$sum:1}
}
}
])
db.stu.aggregate([
{$group:
{
_id:null,
counter:{$sum:1},
avgAge:{$avg:‘$age‘}
}
}
])
db.stu.aggregate([
{$group:
{
_id:‘$gender‘,
name:{$push:‘$name‘}
}
}
])
db.stu.aggregate([
{$group:
{
_id:‘$gender‘,
name:{$push:‘$$ROOT‘}
}
}
])
db.stu.aggregate([
{$match:{age:{$gt:20}}}
])
db.stu.aggregate([
{$match:{age:{$gt:20}}},
{$group:{_id:‘$gender‘,counter:{$sum:1}}}
])
db.stu.aggregate([
{$project:{_id:0,name:1,age:1}}
])
db.stu.aggregate([
{$group:{_id:‘$gender‘,counter:{$sum:1}}},
{$project:{_id:0,counter:1}}
])
b.stu.aggregate([{$sort:{age:1}}])
db.stu.aggregate([
{$group:{_id:‘$gender‘,counter:{$sum:1}}},
{$sort:{counter:-1}}
])
db.stu.aggregate([{$limit:2}])
db.stu.aggregate([{$skip:2}])
db.stu.aggregate([
{$group:{_id:‘$gender‘,counter:{$sum:1}}},
{$sort:{counter:1}},
{$skip:1},
{$limit:1}
])
db.集合名称.aggregate([{$unwind:‘$字段名称‘}])
db.t2.insert({_id:1,item:‘t-shirt‘,size:[‘S‘,‘M‘,‘L‘]})
db.t2.aggregate([{$unwind:‘$size‘}])
db.inventory.aggregate([{
$unwind:{
path:‘$字段名称‘,
preserveNullAndEmptyArrays:<boolean>#防止数据丢失
}
}])
db.t3.insert([
{ "_id" : 1, "item" : "a", "size": [ "S", "M", "L"] },
{ "_id" : 2, "item" : "b", "size" : [ ] },
{ "_id" : 3, "item" : "c", "size": "M" },
{ "_id" : 4, "item" : "d" },
{ "_id" : 5, "item" : "e", "size" : null }
])
db.t3.aggregate([{$unwind:‘$size‘}])
db.t3.aggregate([{$unwind:{path:‘$sizes‘,preserveNullAndEmptyArrays:true}}])
标签:mongo res vga 标准 数组类 roo path bsp insert
原文地址:https://www.cnblogs.com/LiuYanYGZ/p/12239524.html