相关文章推荐
谦和的机器人  ·  Azure Database for ...·  1 年前    · 
大气的木瓜  ·  Git HEAD detached ...·  1 年前    · 
会开车的草稿本  ·  error when i am ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm trying to merge subdocument values ​​into a collection, but I can't seem to find a way to do that. I have the following collection in MongoDB 4.0:

"_id": "603f8c970f25800300a6c16e", "Hash": "vkqsgIPmB4/am4KJkERghDmmCUXEZjrGQxdCF3Fll2brR0YxJSXeTg==", "Components": [ "FieldA": "A-1", "FieldB": "B-1" "FieldA": "A-2", "FieldB": "B-2" "_id": "609f8c970f25800300a7c16e", "Hash": "vkqsgIPmB4/am4KJkERghDmmCUXEZjrGQxdCF3Fll2brR0sddggdTs==", "Components": [ "FieldA": "A-3", "FieldB": "B-3" "FieldA": "A-4", "FieldB": "B-4"

From this collection I would like to get the following result, where the id would be fed by the value of the main document, and the other fields would be fed by the subdocuments.

"_id":"603f8c970f25800300a6c16e", "FieldA":"A-1", "FieldB":"B-1" "_id":"603f8c970f25800300a6c16e", "FieldA":"A-2", "FieldB":"B-2" "_id":"609f8c970f25800300a7c16e", "FieldA":"A-3", "FieldB":"B-3" "_id":"609f8c970f25800300a7c16e", "FieldA":"A-4", "FieldB":"B-4"

Thanks in advance!

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .