Example #1
0
SEXP rmongo_insert_batch(SEXP mongo_conn, SEXP ns, SEXP b) {
    mongo* conn = _checkMongo(mongo_conn);
    const char* _ns = CHAR(STRING_ELT(ns, 0));
    SEXP ret;
    PROTECT(ret = allocVector(LGLSXP, 1));
    if (TYPEOF(b) != VECSXP)
        error("Expected a list of mongo.bson class objects");
    int len = LENGTH(b);
    bson** blist = Calloc(len, bson*);
    int i;
    int success = 1;
    for (i = 0; i < len && success; i++) {
        SEXP _b = VECTOR_ELT(b, i);
        if (!_isBSON(_b))
            success = 0;
        else
            blist[i] = _checkBSON(_b);
    }
    if (success)
        LOGICAL(ret)[0] = (mongo_insert_batch(conn, _ns, blist, len) == MONGO_OK);
    Free(blist);
    if (!success)
        error("Expected list of mongo.bson class objects");
    UNPROTECT(1);
    return ret;
}
Example #2
0
SEXP mongo_index_create(SEXP mongo_conn, SEXP ns, SEXP key, SEXP options) {
    mongo* conn = _checkMongo(mongo_conn);
    const char* _ns = CHAR(STRING_ELT(ns, 0));
    int _options = 0;
    int i;
    int len = LENGTH(options);
    for (i = 0; i < len; i++)
        _options |= INTEGER(options)[i];
    bson* _key;
    bson b;
    int keyIsBSON = _isBSON(key);
    if (keyIsBSON)
        _key = _checkBSON(key);
    else {
        _key = &b;
        len = LENGTH(key);
        bson_init(&b);
        for (i = 0; i < len; i++)
            bson_append_int(&b, CHAR(STRING_ELT(key, i)), 1);
        bson_finish(&b);
    }
    bson out;
    int success = mongo_create_index(conn, _ns, _key, _options, &out);
    if (!keyIsBSON)
        bson_destroy(&b);
    if (success == MONGO_OK) {
        bson_destroy(&out);
        return R_NilValue;
    }
    SEXP ret = _mongo_bson_create(&out);
    bson_destroy(&out);
    UNPROTECT(3);
    return ret;
}
Example #3
0
SEXP mongo_gridfs_find(SEXP gfs, SEXP query) {
    gridfs* _gfs = _checkGridfs(gfs);
    gridfile* gfile = Calloc(1, gridfile);
    int result;
    if (_isBSON(query)) {
        bson* _query = _checkBSON(query);
        result = gridfs_find_query(_gfs, _query, gfile);
    } else
        result = gridfs_find_filename(_gfs, CHAR(STRING_ELT(query, 0)), gfile);
    if (result != MONGO_OK)
        return R_NilValue;
    return _mongo_gridfile_create(gfs, gfile);
}