时间:2021-07-01 10:21:17 帮助过:5人阅读
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}}])
MongoDB 2、高级操作
标签:mongo res vga 标准 数组类 roo path bsp insert