0

I am using mongodb 3.0.4. I have a collection of documents where site field is object. How can I convert this field to array?

{
  "_id": 123,
  "site": {"name": "a", "direction: "in"}
}
{
  "_id": 321,
  "site": [{"name": "a", "direction": "in"}]
}
3
  • You can use square brackets [] directly to create array if you can upgrade to 3.2.
    – s7vr
    Aug 15, 2018 at 11:44
  • You can add a $group by id with push operator in lower version to create an array.
    – s7vr
    Aug 15, 2018 at 11:52
  • Thanks for the reply. Is $group the only way in mongodb 3.0.4. Using grouped by id is kind of sad...
    – Junkai Niu
    Aug 15, 2018 at 13:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.