Let's say you have an array dataset:
[{
"name": "Simon",
"hobbies": ["badminton", "tennis"]
},{
"name": "Max",
"hobbies": ["swimming", "tennis"]
}]
You can fatten the hobbies array to multiple documents using $unwind.
db.hobby.aggregate([{$unwind : "$hobbies"}]).pretty()
The result:
[{
"_id" : ObjectId("6066d4146fc1865ad270a066"),
"name" : "Simon",
"hobbies" : "badminton"
},
{
"_id" : ObjectId("6066d4146fc1865ad270a066"),
"name" : "Simon",
"hobbies" : "tennis"
},
{
"_id" : ObjectId("6066d42b6fc1865ad270a067"),
"name" : "Max",
"hobbies" : "swimming"
},
{
"_id" : ObjectId("6066d42b6fc1865ad270a067"),
"name" : "Max",
"hobbies" : "tennis"
}]
Let produce the same data set in HCL Notes.
No comments:
Post a Comment