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.

Était-ce utile?

La solution

You could simply use $project function from aggregate framework:

db.collection.aggregate([
    {$project:{
        field1:"$rec.field1",
        field2:"$rec.field2",
        field3:"$rec.field3"}
    }
])
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top