0

I'm migrating from Legacy Realm and its Realm.Sync listeners to Change Streams and I'm trying to figure out how to easily fetch the full objects returned on update.

 case "update": {
      const { documentKey, fullDocument } = change;
      console.log(`updated document: ${documentKey}`, fullDocument);
      break;
    }

Is there a way to fetch the full document with the relationship data?

For example the fullDocument:

{
  "_id": "b03dcd5d-94dc-7254-6aff-44d5818390ca",
  "_partition": "test"
  "Message": "Test",
  "Sender": "51f717ad-afbc-c3d6-779a-72db53f8b708",
  "SeenBy": [
    "51f717ad-afbc-c3d6-779a-72db53f8b708"
  ],
}

Instead of the Sender id, I want to get the sender document, same thing in SeenBy.

{
  "_id": "b03dcd5d-94dc-7254-6aff-44d5818390ca",
  "_partition": "test"
  "Message": "Test",
  "Sender": {"_id": "51f717ad-afbc-c3d6-779a-72db53f8b708", "Name":"John"},
  "SeenBy": [
    {"_id": "51f717ad-afbc-c3d6-779a-72db53f8b708", "Name":"John"}
  ],
}
Buzzkill
  • 68
  • 2
  • 8

1 Answers1

0

If you want to bring in data from other collections, you need to retrieve it separately from the change stream. Change stream allows specifying several aggregation pipeline stages but $lookup is not one of them.

D. SM
  • 13,584
  • 3
  • 12
  • 21