Can you please clarify what too many documents means in this context? The deleteMany({}) command is executed as a function call from the SDK, and as such is subject to the constraints for functions. If you’re on a low tier, you’re also subject to limitations of your throughput: the combinations of these factors dictates the limits you’re likely hitting. Raising the tier would certainly help, you should take into consideration how frequent this type of operation is to size the app properly.
Why via mongodriver does not have this problem? Mongodriver works much better, but then you can’t work with permissions with users… Or rather you can, but limited to 100 database users.
I’ve tried to reproduce the issue, and indeed there’s an odd behaviour for the deleteMany(…) function, when called from the SDK: we’ll raise an internal ticket for this.
As a workaround, you can try to implement your own Realm function within your app on the portal, something like, say, wipeCollection defined as
They aren’t meant to overlap, the functionality you’ve been using (MongoDB Data Access) is built for convenience to allow simple interaction with the remote DB, however, from a mobile device, the developer will likely either:
Use the powerful local object DB that Realm provides, with automatic synching with the backend, powered by MongoDB (Mobile-first approach): DB logic is then at home on the device, with the possibility of some further processing on the backend, if needed.
Build an online-only app by leveraging the backend functionality, with Triggers, Functions, Webhooks, … (Backend-first approach): the Functions will have the full access to the MongoDB Driver, implement the core logic, and at the same time deliver a clean and secure range of services to the mobile side, without the risk of allowing full access to the DB from mobile clients.
This code works perfectly with thousands of ReplaceOne expressions at once (20.000). But if I try to write a Function that does this and send thousands of ReplaceOne expressions through the Realm client, I get an error and get disconnected due to the large amount of information. Even with just hundreds of expressions.
Functions will have full access to MongoDB driver, but MongoDB driver client performance is better in this case with BulkWrite.
The reason is that, when Sync is enabled on a collection, every change needs to be recorded to be transmitted to the mobile clients, that will in turn reflect that change on the local DB (see the Mobile-first approach I indicated in an earlier comment). This process limits the amount of changes that can be recorded in a given time, before the Function hits the timeout.
If, OTOH, you plan to use the Backend-first approach, and handle everything via Functions/Webhooks/…, with no local DB on the devices, then having Sync active makes little sense, and you can get a better performance (within the Service Limitations, obviously) by disabling it.