Advertisement

MongoDB实战聚合管道:$unwind

阅读量:

** $unwind:将文档中某一数组字段展开为多条记录,每条记录对应数组中的单个元素。**

在进行项目开发过程中,遇到了如下需求:

**
**

实例讲解:


复制代码
 {

    
     "_id" : ObjectId("5951c5de567ebff0d5011fba"),
    
     "name" : "陈晓婵",
    
     "address" : "北京朝阳区",
    
     "weekday" : [ 
    
     1, 
    
     2, 
    
     3, 
    
     4, 
    
     5
    
     ]
    
 }
    
    
    
    

对weekday这一变量进行分解处理:

复制代码
  db.getCollection('chenxiaochantest').aggregate(

    
  [
    
   {
    
      $unwind:"$weekday"
    
   }
    
  ]
    
 )
    
    
    
    

拆分结果:


复制代码
  /* 1 */

    
 {
    
     "_id"

全部评论 (0)

还没有任何评论哟~