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.

Was it helpful?

Solution

You could simply use $project function from aggregate framework:

db.collection.aggregate([
    {$project:{
        field1:"$rec.field1",
        field2:"$rec.field2",
        field3:"$rec.field3"}
    }
])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top