How to remove objects from local realm database after they have been written to the atlas database?

I have a collection in which documents are written online when from our nodeJS backend using mongoose. In order to support offline mode, I am using realm to create documents locally in the react native app and store in realm which in turn syncs it with the Atlas database. But, now I want to remove created document from the local realm database as it is no longer of use. Also, I want to restrict the documents created from the backend to be written to the sync as it will unnecessarily increase my storage consumption.

I have two solutions for the above:

  1. Use a boolean in the collection which is changed in a trigger when the documents syncs with the Atlas database. I use this as a filter in the local realm query to remove it from the local database. However, this still leads to the unnecessary write of documents created from backend to sync database.
  2. Use asymmetric sync to only write the documents from client to Atlas. I am unable to find a way to delete it from the local database in this case after it is written to atlas database.

I am not a node-js guy but I think the question needs some clarity as the expected outcome is unclear.

The question states you have synced situation - data is written locally and synced to the server.

You want to delete local data but then not delete it on the server? That goes against a synced database because they would then be out of sync.

Then you’re wanting to create documents on the server but not have then sync locally - again, that would not be a synced database.

Can you clarify your desired outcome a bit?