/** * mongo_bson_new: * * Creates a new instance of #MongoBson. The #MongoBson instance is * pre-populated with an _id field and #MongoObjectId value. This value * is generated on the local machine and follows the guidelines suggested * by the BSON ObjectID specificiation. * * Returns: A #MongoBson that should be freed with mongo_bson_unref(). */ MongoBson * mongo_bson_new (void) { MongoObjectId *oid; MongoBson *bson; bson = mongo_bson_new_empty(); oid = mongo_object_id_new(); mongo_bson_append_object_id(bson, "_id", oid); mongo_object_id_free(oid); return bson; }
void mongo_cursor_count_async (MongoCursor *cursor, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { MongoCursorPrivate *priv; GSimpleAsyncResult *simple; MongoBson *command; ENTRY; g_return_if_fail(MONGO_IS_CURSOR(cursor)); g_return_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable)); g_return_if_fail(callback); priv = cursor->priv; if (!priv->connection) { g_simple_async_report_error_in_idle(G_OBJECT(cursor), callback, user_data, MONGO_CONNECTION_ERROR, MONGO_CONNECTION_ERROR_NOT_CONNECTED, _("Cursor is missing MongoConnection.")); EXIT; } simple = g_simple_async_result_new(G_OBJECT(cursor), callback, user_data, mongo_cursor_count_async); g_simple_async_result_set_check_cancellable(simple, cancellable); command = mongo_bson_new_empty(); mongo_bson_append_string(command, "count", priv->collection); if (priv->query) { mongo_bson_append_bson(command, "query", priv->query); } mongo_connection_command_async(priv->connection, priv->database, command, cancellable, mongo_cursor_count_cb, simple); mongo_bson_unref(command); EXIT; }