سؤال

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.

هل كانت مفيدة؟

المحلول

You could simply use $project function from aggregate framework:

db.collection.aggregate([
    {$project:{
        field1:"$rec.field1",
        field2:"$rec.field2",
        field3:"$rec.field3"}
    }
])
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top