Duplicate entire Realm partition

I currently have a Realm with all user data utilizing the user=id style of partition.

I want to create a new Realm with all of the user data that was in the old partition with a new user.

Is there a straightforward way to query for all of the objects with a given partition string and then copy them into a new partition, obviously replacing the _partition with the new user=new_id and the _id with a new uuid?

1 Like

Is this Realm Sync (seems to be) or local only? Also, what platform if local?

Sorry @Jay, should have mentioned that I’m attempting to do this in a Realm Function with a synced Realm.

Thought that was implied since that’s why partitions exist.

Locally I’m using React Native, but that shouldn’t matter for the server function.

I’m currently trying to figure out how to do this with the .aggregation method on each collection. No idea if this is a good method, but without any input, just trying things. Would appreciate any input from the Realm team.