SEXP R_raw_to_bson(SEXP buf){ bson_error_t err; bson_t *b = bson_new_from_data(RAW(buf), length(buf)); if(!b) stop(err.message); return bson2r(b); }
SEXP R_json_to_bson(SEXP json){ bson_t *b; bson_error_t err; b = bson_new_from_json ((uint8_t*)translateCharUTF8(asChar(json)), -1, &err); if(!b) stop(err.message); return bson2r(b); }
SEXP R_mongo_cursor_next_bson (SEXP ptr){ mongoc_cursor_t *c = r2cursor(ptr); const bson_t *b = NULL; if(!mongoc_cursor_next(c, &b)){ bson_error_t err; if(mongoc_cursor_error (c, &err)) stop(err.message); else return R_NilValue; } return bson2r((bson_t*) b); }