I have a Mongo collection where I need to move an array of objects into a separate collection.
The collection is in this format:
{
_id: ObjectId("..."),
name: "...",
description: "...",
widgets: [
{ someprop: somevalue },
{ someprop: somevalue }
]
}
I'd like to unwind the object array into a separate collection.
According to the documentation for $out at http://docs.mongodb.org/manual/reference/operator/aggregation/out/ I should be able to use the operator to create a new collection.
The first two operations in the following Mongo shell command work to unwind the array into a list but it fails when I add the $out operation:
db.mytable.aggregate([
{ $project : {_id: 0, datasets : 1}},
{ $unwind : "$widgets"},
{ $out: "widgets"}
]);
Error:
Error: command failed: {
"errmsg" : "exception: Unrecognized pipeline stage name: '$out'",
"code" : 16436,
"ok" : 0
} : aggregate failed at src/mongo/shell/assert.js:13
Make sure you're using the latest version. $out is new in 2.6, using 2.6.2 worked perfectly for me !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With