예제 #1
0
cursor collection::aggregate(const pipeline& pipeline, const options::aggregate& options) {
    using namespace bsoncxx::builder::stream;

    scoped_bson_t stages(pipeline._impl->view());

    bsoncxx::builder::stream::document b;

    if (options.allow_disk_use()) {
        b << "allowDiskUse" << *options.allow_disk_use();
    }

    if (options.use_cursor()) {
        auto inner = b << "cursor" << open_document;

        if (options.batch_size()) {
            inner << "batchSize" << *options.batch_size();
        }

        inner << close_document;
    }

    if (options.max_time()) {
        b << "maxTimeMS" << bsoncxx::types::b_int64{options.max_time()->count()};
    }

    if (options.bypass_document_validation()) {
        b << "bypassDocumentValidation" << *options.bypass_document_validation();
    }

    scoped_bson_t options_bson(b.view());

    const ::mongoc_read_prefs_t* rp_ptr = NULL;

    if (options.read_preference()) {
        rp_ptr = read_preference()._impl->read_preference_t;
    }

    return cursor(libmongoc::collection_aggregate(_get_impl().collection_t,
                                                  static_cast<::mongoc_query_flags_t>(0),
                                                  stages.bson(), options_bson.bson(), rp_ptr));
}
예제 #2
0
cursor collection::aggregate(const pipeline& pipeline, const options::aggregate& options) {
    scoped_bson_t stages(bsoncxx::document::view(pipeline._impl->view_array()));

    bsoncxx::builder::basic::document b;

    if (options.allow_disk_use()) {
        b.append(kvp("allowDiskUse", *options.allow_disk_use()));
    }

    if (options.collation()) {
        b.append(kvp("collation", *options.collation()));
    }

    if (options.use_cursor()) {
        b.append(kvp("cursor", [&options](sub_document sub_doc) {
            if (options.batch_size()) {
                sub_doc.append(kvp("batchSize", *options.batch_size()));
            }
        }));
    }

    if (options.max_time()) {
        b.append(kvp("maxTimeMS", bsoncxx::types::b_int64{options.max_time()->count()}));
    }

    if (options.bypass_document_validation()) {
        b.append(kvp("bypassDocumentValidation", *options.bypass_document_validation()));
    }

    scoped_bson_t options_bson(b.view());

    const ::mongoc_read_prefs_t* rp_ptr = NULL;

    if (options.read_preference()) {
        rp_ptr = options.read_preference()->_impl->read_preference_t;
    }

    return cursor(libmongoc::collection_aggregate(_get_impl().collection_t,
                                                  static_cast<::mongoc_query_flags_t>(0),
                                                  stages.bson(),
                                                  options_bson.bson(),
                                                  rp_ptr));
}