bool _mongoc_cursor_prepare_getmore_command (mongoc_cursor_t *cursor, bson_t *command) { const char *collection; int collection_len; ENTRY; _mongoc_cursor_collection (cursor, &collection, &collection_len); bson_init (command); bson_append_int64 (command, "getMore", 7, mongoc_cursor_get_id (cursor)); bson_append_utf8 (command, "collection", 10, collection, collection_len); if (cursor->batch_size) { bson_append_int64 (command, "batchSize", 9, cursor->batch_size); } /* Find, getMore And killCursors Commands Spec: "In the case of a tailable cursor with awaitData == true the driver MUST provide a Cursor level option named maxAwaitTimeMS (See CRUD specification for details). The maxTimeMS option on the getMore command MUST be set to the value of the option maxAwaitTimeMS. If no maxAwaitTimeMS is specified, the driver SHOULD not set maxTimeMS on the getMore command." */ if (cursor->flags & MONGOC_QUERY_TAILABLE_CURSOR && cursor->flags & MONGOC_QUERY_AWAIT_DATA && cursor->max_await_time_ms) { bson_append_int32 (command, "maxTimeMS", 9, cursor->max_await_time_ms); } RETURN (true); }
bool _mongoc_cursor_prepare_getmore_command (mongoc_cursor_t *cursor, bson_t *command) { const char *collection; int collection_len; int64_t batch_size; bool await_data; int32_t max_await_time_ms; ENTRY; _mongoc_cursor_collection (cursor, &collection, &collection_len); bson_init (command); bson_append_int64 (command, "getMore", 7, mongoc_cursor_get_id (cursor)); bson_append_utf8 (command, "collection", 10, collection, collection_len); batch_size = mongoc_cursor_get_batch_size (cursor); /* See find, getMore, and killCursors Spec for batchSize rules */ if (batch_size) { bson_append_int64 ( command, MONGOC_CURSOR_BATCH_SIZE, MONGOC_CURSOR_BATCH_SIZE_LEN, abs (_mongoc_n_return (cursor))); } /* Find, getMore And killCursors Commands Spec: "In the case of a tailable cursor with awaitData == true the driver MUST provide a Cursor level option named maxAwaitTimeMS (See CRUD specification for details). The maxTimeMS option on the getMore command MUST be set to the value of the option maxAwaitTimeMS. If no maxAwaitTimeMS is specified, the driver SHOULD not set maxTimeMS on the getMore command." */ await_data = _mongoc_cursor_get_opt_bool (cursor, MONGOC_CURSOR_TAILABLE) && _mongoc_cursor_get_opt_bool (cursor, MONGOC_CURSOR_AWAIT_DATA); if (await_data) { max_await_time_ms = (int32_t) mongoc_cursor_get_max_await_time_ms (cursor); if (max_await_time_ms) { bson_append_int32 ( command, MONGOC_CURSOR_MAX_TIME_MS, MONGOC_CURSOR_MAX_TIME_MS_LEN, max_await_time_ms); } } RETURN (true); }