Merge Multiple Documents in realm

Hi Team,

I have below three documents retrieved from three collections -
{ fulldocument }

Need to merge in one and insert in elastic search like below -
{ fulldocument,

I am not able to merge it in one document.
I can do it by adding one by one attribute but want to add it as document.


Hi @gopinath_maheswaran,

Check the option of running aggregation with $mergeObjects:

Potentially you can use $unionWith from the three collection and group by null. Last stage can be the merge objects.


Thanks for the suggestion!,

I tried multiple options,

  1. $mergeObject
    output - {$mergeObject: { fulldocument},

root is creating with $mergeObject name and it’s list of object in one object.

  1. Object.assign -
    output -{$set: { fulldocument,

root is creating with $set.

but in both scenario after data insert in elastic search output for all the integer data is like below -
“downloads”: {
“$numberInt”: “10”

expected result - “downloads”: 10

Elastic search output is working expected if data is inserting through postman.


This is expected as it is Extended Json represention…

How do you fetch the data ? Is it through a Driver or a Realm function? (Now noticed Realm case type)

Of its from a function or a webhook you need to JSON.stringify output :

docs = await coll.find()