Updating linked atlas documents problems

I’ve been battling this for a few days so figured I’d just ask! I’m new to Realms/Mongo so it’s probably something simple. I had a quick search and I couldn’t find something similar.

I’m following the guide here:

On how to update a document in a linked atlas collection using a realm connection. The docs seem to say create a Document(…) for the query and a Document(…) specifying the values you wish to update.

The behaviour I seem to be seeing is that the new Document replaces the matching document rather than updating matching fields. Just wondering what I could be doing wrong?

The screenshots attached are from Atlas/Realm website with me trying to query for Document(“name”, “russian”) and updating with Document(“difficulty”, 99). The query in the realm log looks like I would expect and indeed this works if I perform a similar update on the console.

I can only upload one photo apparently, so sorry for the bodged paint job :wink:

Is there something I am missing? The only way I can seem to get this to work is to populate all the original fields in the update query which is tedious. This is all on Android but I think it’s something more fundamental that I am missing… Maybe some setting or something silly?


Hey Steven, welcome to the forums! :wave:t3:

The update document supports update operators like $set which updates a single field without modifying the rest of the document. You’ll want to use that or another update operator, e.g.

Document("$set", Document("difficulty", 99));

The behavior you’re seeing (replace the full document) is expected based on the update documents in the docs example because they don’t include update operators. That said the example is incomplete and we can do better. I just made a docs ticket and will follow up to make sure we get better examples that show update operators.

1 Like

Hey Nick! Thanks for the warm welcome :wave:

Ah that does make sense now that you mention there are different update operators you can perform… I knew it would be something simple! I do now also see the link for the update operators just above. But I wouldn’t have guessed to do Document("$set", Document(…))…

Thanks for saving me some more days of frustration! :blush:


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.