Esempio n. 1
0
SEXP rmongo_find(SEXP mongo_conn, SEXP ns, SEXP query, SEXP sort, SEXP fields, SEXP limit, SEXP skip, SEXP options) {
    mongo* conn = _checkMongo(mongo_conn);
    const char* _ns = CHAR(STRING_ELT(ns, 0));
    bson* _query = _checkBSON(query);
    bson* _sort = _checkBSON(sort);

    bson* q = _query;
    bson sorted_query;
    if (_sort != NULL && bson_size(_sort) > 5) {
        q = &sorted_query;
        bson_init(q);
        bson_append_bson(q, "$query", _query);
        bson_append_bson(q, "$orderby", _sort);
        bson_finish(q);
    }

    bson* _fields = _checkBSON(fields);
    int _limit = asInteger(limit);
    int _skip = asInteger(skip);
    int _options = 0;
    int i;
    int len = LENGTH(options);
    for (i = 0; i < len; i++)
        _options |= INTEGER(options)[i];

    mongo_cursor* cursor = mongo_find(conn, _ns, q, _fields, _limit, _skip, _options);

    if (q == &sorted_query)
        bson_destroy(&sorted_query);

    return _mongo_cursor_create(cursor);
}
Esempio n. 2
0
SEXP mongo_gridfile_get_chunks(SEXP gfile, SEXP start, SEXP count) {
    gridfile* _gfile = _checkGridfile(gfile);
    int _start = asInteger(start);
    int _count = asInteger(count);
    mongo_cursor* cursor = gridfile_get_chunks(_gfile, _start, _count);
    return _mongo_cursor_create(cursor);
}