MONGOC_CURSOR_...EPLY_WITH_OPTS(3)

πŸ’… MONGOC_CURSOR_...EPLY_WITH_OPTS(3) β€” aka the libmongoc girlie who got her name cut off mid-glow-up

okay so first things first, bestie: the title of this page is literally truncated in the actual manpage β€” it's giving "my name got clipped in the group chat preview" 😭. It's the libmongoc section 3 page for mongoc_cursor_new_from_command_reply_with_opts, and yes, the header really does read MONGOC_CURSOR_...EPLY_WITH_OPTS(3) on both the top and bottom lines. We move.


✨ SYNOPSIS ✨

mongoc_cursor_t *
mongoc_cursor_new_from_command_reply_with_opts (mongoc_client_t *client,
                                                bson_t *reply,
                                                const bson_t *opts);

🫢 PARAMETERS 🫢

  • client β€” a mongoc_client_t. your connection bestie.
  • reply β€” the reply to a command that returns a cursor document β€” think "aggregate", "find", or "listCollections".
⚠️ lowkey important: the reply is destroyed by mongoc_cursor_new_from_command_reply_with_opts and must not be accessed afterward. like, it's gone, don't text it, don't look at it, it's over πŸ’€
  • opts β€” a bson_t.

opts may be NULL or a BSON document with additional options, which have the same meaning for this function as for mongoc_collection_find_with_opts():

  • awaitData
  • batchSize
  • limit
  • maxAwaitTimeMS
  • serverId
  • sessionId
  • skip
  • tailable

🌸 DESCRIPTION 🌸

So some MongoDB commands return a "cursor" document, right? iconic behavior. For example, given an "aggregate" command:

{ "aggregate" : "collection", "pipeline" : [], "cursor" : {}}

the server replies:

{
   "cursor" : {
      "id" : 1234,
      "ns" : "db.collection",
      "firstBatch" : [ ]
   },
   "ok" : 1
}

mongoc_cursor_new_from_command_reply_with_opts is a low-level function that initializes a mongoc_cursor_t from such a reply. no cap, that's the whole gig.

Now the serverId tea β˜•: when you're synthesizing a completed cursor response that has no more batches (i.e. with cursor id 0), serverId may be 0. But if the cursor response is not completed (i.e. with a non-zero cursor id), pass the serverId of the server that was used to create the cursor. don't fumble that.

🚨 Use this function only for building a language driver that wraps the C Driver. If you're writing applications in C, higher-level functions such as mongoc_collection_aggregate() are way more appropriate, and they ensure compatibility with a range of MongoDB versions. she's a specialist tool, not a daily driver, periodt.

πŸ‘‘ RETURNS πŸ‘‘

A mongoc_cursor_t. On failure, the cursor's error is set. Check for failure with mongoc_cursor_error(). simple as that, bestie.


πŸŽ€ AUTHOR πŸŽ€

MongoDB, Inc

2009-present, MongoDB, Inc.


and that's the whole page! mwah πŸ’–

okay so the sign-off: this little masterpiece is from libmongoc version 2.5.6, dated Oct 09, 202 (yes the date literally got chopped off in the source, we're all just doing our best here πŸ™ˆ), and it's filed under MONGOC_CURSOR_...EPLY_WITH_OPTS(3) at the bottom too because consistency is a vibe. go forth and cursor responsibly πŸ§šβ€β™€οΈβ­

πŸ“¦ where this page comes from