#include <Cursor.h>
An abstraction for MongoDB answer cursors.
Definition at line 18 of file Cursor.h.
◆ Cursor() [1/4]
Cursor::Cursor |
( |
const std::shared_ptr< Collection > & |
collection | ) |
|
|
explicit |
Definition at line 15 of file Cursor.cpp.
16 : collection_(collection),
18 isAggregateQuery_(
false),
22 collection_->appendSession(opts_);
25 ss << static_cast<const void *>(
this);
◆ Cursor() [2/4]
knowrob::mongo::Cursor::Cursor |
( |
const Cursor & |
| ) |
|
|
delete |
◆ ~Cursor() [1/2]
Definition at line 29 of file Cursor.cpp.
30 if (cursor_ !=
nullptr) {
31 mongoc_cursor_destroy(cursor_);
34 if (query_ !=
nullptr) {
38 if (opts_ !=
nullptr) {
◆ Cursor() [3/4]
knowrob::mongo::Cursor::Cursor |
( |
const std::shared_ptr< Collection > & |
collection | ) |
|
|
explicit |
◆ Cursor() [4/4]
knowrob::mongo::Cursor::Cursor |
( |
const Cursor & |
| ) |
|
|
delete |
◆ ~Cursor() [2/2]
knowrob::mongo::Cursor::~Cursor |
( |
| ) |
|
◆ aggregate() [1/2]
void Cursor::aggregate |
( |
const bson_t * |
query_doc | ) |
|
Run an aggregation pipeline to obtain results for this Cursor.
- Parameters
-
Definition at line 62 of file Cursor.cpp.
63 isAggregateQuery_ =
true;
64 bson_concat(query_, query_doc);
◆ aggregate() [2/2]
void knowrob::mongo::Cursor::aggregate |
( |
const bson_t * |
query_doc | ) |
|
Run an aggregation pipeline to obtain results for this Cursor.
- Parameters
-
◆ ascending() [1/2]
void Cursor::ascending |
( |
const char * |
key | ) |
|
Sort results in ascending order.
- Parameters
-
key | a field name in result documents. |
Definition at line 48 of file Cursor.cpp.
49 static bson_t *doc = BCON_NEW(
"sort",
"{", key, BCON_INT32(1),
"}");
50 bson_concat(opts_, doc);
◆ ascending() [2/2]
void knowrob::mongo::Cursor::ascending |
( |
const char * |
key | ) |
|
Sort results in ascending order.
- Parameters
-
key | a field name in result documents. |
◆ descending() [1/2]
void Cursor::descending |
( |
const char * |
key | ) |
|
Sort results in descending order.
- Parameters
-
key | a field name in result documents. |
Definition at line 53 of file Cursor.cpp.
54 static bson_t *doc = BCON_NEW(
"sort",
"{", key, BCON_INT32(-1),
"}");
55 bson_concat(opts_, doc);
◆ descending() [2/2]
void knowrob::mongo::Cursor::descending |
( |
const char * |
key | ) |
|
Sort results in descending order.
- Parameters
-
key | a field name in result documents. |
◆ erase() [1/2]
Erase all documents that are result documents of this Cursor.
- Returns
- true on success.
Definition at line 98 of file Cursor.cpp.
100 bool success = mongoc_collection_delete_many(
101 collection_->coll(), query_, opts_,
nullptr , &err);
◆ erase() [2/2]
bool knowrob::mongo::Cursor::erase |
( |
| ) |
|
Erase all documents that are result documents of this Cursor.
- Returns
- true on success.
◆ filter() [1/2]
void Cursor::filter |
( |
const bson_t * |
query_doc | ) |
|
Filter results of the getAnswerCursor by the pattern provided.
- Parameters
-
query_doc | a query document. |
Definition at line 58 of file Cursor.cpp.
59 bson_concat(query_, query_doc);
◆ filter() [2/2]
void knowrob::mongo::Cursor::filter |
( |
const bson_t * |
query_doc | ) |
|
Filter results of the getAnswerCursor by the pattern provided.
- Parameters
-
query_doc | a query document. |
◆ id() [1/2]
const auto& knowrob::mongo::Cursor::id |
( |
| ) |
|
|
inline |
◆ id() [2/2]
const auto& knowrob::mongo::Cursor::id |
( |
| ) |
|
|
inline |
◆ limit() [1/2]
void Cursor::limit |
( |
unsigned int |
limit | ) |
|
Limit results produced by this Cursor.
- Parameters
-
limit | the maximum number of results. |
Definition at line 44 of file Cursor.cpp.
void limit(unsigned int limit)
◆ limit() [2/2]
void knowrob::mongo::Cursor::limit |
( |
unsigned int |
limit | ) |
|
Limit results produced by this Cursor.
- Parameters
-
limit | the maximum number of results. |
◆ next() [1/2]
bool Cursor::next |
( |
const bson_t ** |
doc, |
|
|
bool |
ignore_empty = false |
|
) |
| |
Start the query if it has not been started yet and generate the next result document.
- Parameters
-
doc | pointer to result document. |
ignore_empty | |
- Returns
- true on success
Definition at line 67 of file Cursor.cpp.
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)) {
◆ next() [2/2]
bool knowrob::mongo::Cursor::next |
( |
const bson_t ** |
doc, |
|
|
bool |
ignore_empty = false |
|
) |
| |
Start the query if it has not been started yet and generate the next result document.
- Parameters
-
doc | pointer to result document. |
ignore_empty | |
- Returns
- true on success
◆ query() [1/2]
const auto* knowrob::mongo::Cursor::query |
( |
| ) |
const |
|
inline |
- Returns
- the bson_t object associated to this Cursor.
Definition at line 78 of file Cursor.h.
◆ query() [2/2]
const auto* knowrob::mongo::Cursor::query |
( |
| ) |
const |
|
inline |
- Returns
- the bson_t object associated to this Cursor.
Definition at line 78 of file Cursor.h.
The documentation for this class was generated from the following files:
- build/_CPack_Packages/Linux/DEB/knowrob-2.1.0-Linux/usr/include/knowrob/storage/mongo/Cursor.h
- src/storage/mongo/Cursor.cpp