EduardoRL
EduardoRL

Reputation: 559

Change the structure of a document

I have this document structure:

{
    "a":{
        "b":{
            "c":"Eduardo","d":"Romero"
            }
        }
}

How do I get this results in mongodb language?

{"c":"Eduardo","d":"Romero"}

Thank very much in advance

Upvotes: 1

Views: 55

Answers (1)

mickl
mickl

Reputation: 49945

You need $replaceRoot pipeline stage, try:

db.col.aggregate([ { $replaceRoot: { newRoot: "$a.b" } } ])

Upvotes: 1

Related Questions