0

I have a really deep-nested JSON object generated by aggregation query, but I want to convert all the object ids to string format. Tried $toString in $addFields and $project. Since the object is nested and contains an array of objects with object id. It's difficult to do using this. Is there any other way by which I can convert all object ids to string in MongoDB during querying?

2
  • Is unwind -> modify -> group an option?
    – Joe
    Aug 19 at 18:08
  • Nope @Joe this was not necessary. Please see the answer below Aug 25 at 9:05
0

I have used the $addFields and $project operators to solve this. Although it took time. But the issue is resolved.

Reference:

https://docs.mongodb.com/manual/reference/operator/aggregation/project/

https://docs.mongodb.com/manual/reference/operator/aggregation/addFields/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.