You could simply use $project
function from aggregate framework:
db.collection.aggregate([
{$project:{
field1:"$rec.field1",
field2:"$rec.field2",
field3:"$rec.field3"}
}
])
Question
using, mongodb aggreate framework, how can I go from the below:
[
"rec": {
"field1" : "123",
"field2" : "124",
"field3" : "125"
}
// ... more similar records
]
to this:
[
{
"field1" : "123",
"field2" : "124",
"field3" : "125"
}
// ... more similar records
]
Any suggestions much appreciated.
Solution
You could simply use $project
function from aggregate framework:
db.collection.aggregate([
{$project:{
field1:"$rec.field1",
field2:"$rec.field2",
field3:"$rec.field3"}
}
])