MONGOC_CURSOR_..._COMMAND_REPLY(3)
π MONGOC_CURSOR_..._COMMAND_REPLY(3) β the libmongoc girlies know π
okay bestie, sit down, grab a boba, because we're talking about mongoc_cursor_new_from_command_reply() from libmongoc β yes that's the manual name, and yes it's a whole mouthful, iykyk π«Ά
β οΈ WARNING β οΈ (read this first fr fr)
Deprecated since version 1.11.0 π Use mongoc_cursor_new_from_command_reply_with_opts() instead. She's the upgraded version, the glow-up, the main character now.
When you migrate from the deprecated mongoc_cursor_new_from_command_reply() to mongoc_cursor_new_from_command_reply_with_opts(), keep this in mind bestie: options that you used to pass inside the reply argument (like "batchSize") have to go in the opts argument instead. Not optional, not a vibe, just how it is π
β¨ SYNOPSIS β¨
mongoc_cursor_t *
mongoc_cursor_new_from_command_reply (mongoc_client_t *client,
bson_t *reply,
uint32_t server_id);
π PARAMETERS π
- client β a
mongoc_client_t. Your client, your girl, your connection to everything π - reply β the reply to a command, like
"aggregate","find", or"listCollections", that returns a cursor document. Heads up: the reply gets destroyed bymongoc_cursor_new_from_command_replyand you must not access it afterward. She's gone, she's not coming back, do not text her π - server_id β the opaque id of the server that was used to execute the command.
πΈ DESCRIPTION πΈ
So some MongoDB commands return a "cursor" document. Iconic behaviour honestly. Like, say you hit her with an "aggregate" command:
{ "aggregate" : "collection", "pipeline" : [], "cursor" : {}}
And the server replies like the queen she is:
{
"cursor" : {
"id" : 1234,
"ns" : "db.collection",
"firstBatch" : [ ]
},
"ok" : 1
}
mongoc_cursor_new_from_command_reply is a low-level function that initializes a mongoc_cursor_t from a reply exactly like that one. And extra options such as "tailable" or "awaitData" can be tucked right into the reply too β she contains multitudes β¨
Now, when you're synthesizing a completed cursor response that has no more batches (i.e. with cursor id 0), server_id may be 0. But if the cursor response is not completed (i.e. with a non-zero cursor id), you pass the server_id of the server used to create the cursor. Match the energy, match the id, no cap π§
Real talk though: use this function only if you're building a language driver that wraps the C Driver. If you're writing applications in C, higher-level functions like mongoc_collection_aggregate() are way more appropriate β and they keep you compatible with a range of MongoDB versions. It's giving "just use the nice one bestie" π
π RETURNS π
A mongoc_cursor_t. If it fails, the cursor's error is set. Check for failure with mongoc_cursor_error() β always do the vibe check, never skip it π
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
and that's the whole page, bestie π you're officially educated, hydrated, and glowing. this was libmongoc version 1.30.13, dated Oct 09, 2024 β thank you for coming to my TED talk, periodt π
β¨π¦
π¦ where this page comes from
- fedora 43: mongo-c-driver-devel 1.30.13-1.fc43 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- fedora 43: mongo-c-driver-devel 1.30.13-1.fc43 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms