6 #include "knowrob/storage/mongo/Cursor.h"
7 #include "knowrob/storage/mongo/MongoException.h"
8 #include "knowrob/reasoner/mongolog/bson_pl.h"
16 : collection_(collection),
18 isAggregateQuery_(false),
22 collection_->appendSession(opts_);
25 ss << static_cast<const void *>(
this);
30 if (cursor_ !=
nullptr) {
31 mongoc_cursor_destroy(cursor_);
34 if (query_ !=
nullptr) {
38 if (opts_ !=
nullptr) {
49 static bson_t *doc = BCON_NEW(
"sort",
"{", key, BCON_INT32(1),
"}");
50 bson_concat(opts_, doc);
54 static bson_t *doc = BCON_NEW(
"sort",
"{", key, BCON_INT32(-1),
"}");
55 bson_concat(opts_, doc);
59 bson_concat(query_, query_doc);
63 isAggregateQuery_ =
true;
64 bson_concat(query_, query_doc);
68 if (cursor_ ==
nullptr) {
69 if (isAggregateQuery_) {
70 cursor_ = mongoc_collection_aggregate(
71 collection_->coll(), MONGOC_QUERY_NONE, query_, opts_,
nullptr );
73 cursor_ = mongoc_collection_find_with_opts(
74 collection_->coll(), query_, opts_,
nullptr );
77 mongoc_cursor_set_limit(cursor_, limit_);
82 if (mongoc_cursor_error(cursor_, &err1)) {
86 if (!mongoc_cursor_next(cursor_, doc)) {
89 if (mongoc_cursor_error(cursor_, &err2)) {
100 bool success = mongoc_collection_delete_many(
101 collection_->coll(), query_, opts_,
nullptr , &err);
Cursor(const std::shared_ptr< Collection > &collection)
void filter(const bson_t *query_doc)
void limit(unsigned int limit)
bool next(const bson_t **doc, bool ignore_empty=false)
void aggregate(const bson_t *query_doc)
void ascending(const char *key)
void descending(const char *key)