Reputation: 1131
Is there a way to group requests to MongoDb?
For example I have one collection.find and three collection.aggregate requests from C# code.
I'm wondering is there a way to combine them and send only one request through the network.
Upvotes: 0
Views: 123
Reputation: 6922
MongoDB's wire protocol is designed for a single operation per message, so there is no support for grouping multiple operations into a single request. The only thing that comes close to this is a bulk insert, but that's really one operation that takes multiple documents.
On a non-sharded MongoDB system, you could conceivably perform multiple server-side operations via a single eval command. This would entail sending MongoDB a JavaScript function that runs multiple operations and then stuffs their results into a single result to be returned. However, I'd be hard-pressed to think of a realistic situation where that'd be preferable to sending multiple requests via your driver (JS is less performant, there are concurrency issues, etc.).
Upvotes: 1