What's the $unwind operator in MongoDB?

后端 未结 6 1098
日久生厌
日久生厌 2020-11-27 12:41

This is my first day with MongoDB so please go easy with me :)

I can\'t understand the $unwind operator, maybe because English is not my native language

6条回答
  •  一个人的身影
    2020-11-27 12:51

    consider the below example to understand this Data in a collection

    {
            "_id" : 1,
            "shirt" : "Half Sleeve",
            "sizes" : [
                    "medium",
                    "XL",
                    "free"
            ]
    }
    

    Query -- db.test1.aggregate( [ { $unwind : "$sizes" } ] );

    output

    { "_id" : 1, "shirt" : "Half Sleeve", "sizes" : "medium" }
    { "_id" : 1, "shirt" : "Half Sleeve", "sizes" : "XL" }
    { "_id" : 1, "shirt" : "Half Sleeve", "sizes" : "free" }
    

提交回复
热议问题