2013-02-02 21:52:49 +01:00
|
|
|
|
//
|
|
|
|
|
// QueryRequest.h
|
|
|
|
|
//
|
|
|
|
|
// Library: MongoDB
|
|
|
|
|
// Package: MongoDB
|
|
|
|
|
// Module: QueryRequest
|
|
|
|
|
//
|
|
|
|
|
// Definition of the QueryRequest class.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
|
|
|
|
// and Contributors.
|
|
|
|
|
//
|
2014-05-04 21:02:42 +02:00
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
2013-02-02 21:52:49 +01:00
|
|
|
|
//
|
|
|
|
|
|
2013-03-12 04:49:54 +01:00
|
|
|
|
|
|
|
|
|
#ifndef MongoDB_QueryRequest_INCLUDED
|
|
|
|
|
#define MongoDB_QueryRequest_INCLUDED
|
|
|
|
|
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
|
|
|
|
#include "Poco/MongoDB/MongoDB.h"
|
|
|
|
|
#include "Poco/MongoDB/RequestMessage.h"
|
2013-02-13 19:10:57 +01:00
|
|
|
|
#include "Poco/MongoDB/Document.h"
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
2013-03-12 04:49:54 +01:00
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
|
namespace Poco {
|
|
|
|
|
namespace MongoDB {
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
2024-07-29 08:16:50 +02:00
|
|
|
|
//class [[deprecated]] QueryRequest;
|
|
|
|
|
class QueryRequest;
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
2017-02-13 15:53:08 +01:00
|
|
|
|
class MongoDB_API QueryRequest: public RequestMessage
|
|
|
|
|
/// A request to query documents in a MongoDB database
|
|
|
|
|
/// using an OP_QUERY request.
|
2013-02-02 21:52:49 +01:00
|
|
|
|
{
|
|
|
|
|
public:
|
2017-02-13 15:53:08 +01:00
|
|
|
|
enum Flags
|
2013-02-02 21:52:49 +01:00
|
|
|
|
{
|
2022-07-07 11:18:20 +02:00
|
|
|
|
QUERY_DEFAULT = 0,
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// Do not set any flags.
|
2022-07-07 11:18:20 +02:00
|
|
|
|
|
|
|
|
|
QUERY_TAILABLE_CURSOR = 2,
|
|
|
|
|
/// Tailable means cursor is not closed when the last data is retrieved.
|
|
|
|
|
/// Rather, the cursor marks the final object’s position.
|
|
|
|
|
/// You can resume using the cursor later, from where it was located,
|
|
|
|
|
/// if more data were received. Like any "latent cursor", the cursor may
|
|
|
|
|
/// become invalid at some point (CursorNotFound) – for example if the final
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// object it references were deleted.
|
2022-07-07 11:18:20 +02:00
|
|
|
|
|
|
|
|
|
QUERY_SLAVE_OK = 4,
|
|
|
|
|
/// Allow query of replica slave. Normally these return an error except
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// for namespace "local".
|
2022-07-07 11:18:20 +02:00
|
|
|
|
|
2017-02-13 15:53:08 +01:00
|
|
|
|
// QUERY_OPLOG_REPLAY = 8 (internal replication use only - drivers should not implement)
|
2022-07-07 11:18:20 +02:00
|
|
|
|
|
2017-02-13 15:53:08 +01:00
|
|
|
|
QUERY_NO_CURSOR_TIMEOUT = 16,
|
2022-07-07 11:18:20 +02:00
|
|
|
|
/// The server normally times out idle cursors after an inactivity period
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// (10 minutes) to prevent excess memory use. Set this option to prevent that.
|
2022-07-07 11:18:20 +02:00
|
|
|
|
|
2013-02-02 21:52:49 +01:00
|
|
|
|
QUERY_AWAIT_DATA = 32,
|
2022-07-07 11:18:20 +02:00
|
|
|
|
/// Use with QUERY_TAILABLECURSOR. If we are at the end of the data, block for
|
|
|
|
|
/// a while rather than returning no data. After a timeout period, we do
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// return as normal.
|
|
|
|
|
|
2013-02-02 21:52:49 +01:00
|
|
|
|
QUERY_EXHAUST = 64,
|
2022-07-07 11:18:20 +02:00
|
|
|
|
/// Stream the data down full blast in multiple "more" packages, on the
|
|
|
|
|
/// assumption that the client will fully read all data queried.
|
|
|
|
|
/// Faster when you are pulling a lot of data and know you want to pull
|
|
|
|
|
/// it all down.
|
|
|
|
|
/// Note: the client is not allowed to not read all the data unless it
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// closes the connection.
|
|
|
|
|
|
2013-02-02 21:52:49 +01:00
|
|
|
|
QUERY_PARTIAL = 128
|
2022-07-07 11:18:20 +02:00
|
|
|
|
/// Get partial results from a mongos if some shards are down
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// (instead of throwing an error).
|
|
|
|
|
};
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
2017-02-13 15:53:08 +01:00
|
|
|
|
QueryRequest(const std::string& collectionName, Flags flags = QUERY_DEFAULT);
|
|
|
|
|
/// Creates a QueryRequest.
|
|
|
|
|
///
|
2022-07-07 11:18:20 +02:00
|
|
|
|
/// The full collection name is the concatenation of the database
|
|
|
|
|
/// name with the collection name, using a "." for the concatenation. For example,
|
|
|
|
|
/// for the database "foo" and the collection "bar", the full collection name is
|
2013-02-02 21:52:49 +01:00
|
|
|
|
/// "foo.bar".
|
|
|
|
|
|
|
|
|
|
virtual ~QueryRequest();
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// Destroys the QueryRequest.
|
2013-02-16 19:56:32 +01:00
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
|
Flags getFlags() const;
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// Returns the flags.
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
|
void setFlags(Flags flag);
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// Set the flags.
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
2013-02-16 19:56:32 +01:00
|
|
|
|
std::string fullCollectionName() const;
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// Returns the <db>.<collection> used for this query.
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
|
Int32 getNumberToSkip() const;
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// Returns the number of documents to skip.
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
|
void setNumberToSkip(Int32 n);
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// Sets the number of documents to skip.
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
|
Int32 getNumberToReturn() const;
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// Returns the number of documents to return.
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
|
void setNumberToReturn(Int32 n);
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// Sets the number of documents to return (limit).
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
2013-02-20 22:20:55 +01:00
|
|
|
|
Document& selector();
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// Returns the selector document.
|
2013-02-16 19:56:32 +01:00
|
|
|
|
|
|
|
|
|
Document& returnFieldSelector();
|
2017-02-13 15:53:08 +01:00
|
|
|
|
/// Returns the field selector document.
|
2013-02-16 19:56:32 +01:00
|
|
|
|
|
2013-02-02 21:52:49 +01:00
|
|
|
|
protected:
|
|
|
|
|
void buildRequest(BinaryWriter& writer);
|
|
|
|
|
|
|
|
|
|
private:
|
2013-03-12 04:49:54 +01:00
|
|
|
|
Flags _flags;
|
2013-02-02 21:52:49 +01:00
|
|
|
|
std::string _fullCollectionName;
|
2013-03-12 04:49:54 +01:00
|
|
|
|
Int32 _numberToSkip;
|
|
|
|
|
Int32 _numberToReturn;
|
|
|
|
|
Document _selector;
|
|
|
|
|
Document _returnFieldSelector;
|
2013-02-02 21:52:49 +01:00
|
|
|
|
};
|
|
|
|
|
|
2013-02-16 19:56:32 +01:00
|
|
|
|
|
2017-02-13 15:53:08 +01:00
|
|
|
|
//
|
|
|
|
|
// inlines
|
|
|
|
|
//
|
2013-02-15 22:32:24 +01:00
|
|
|
|
inline QueryRequest::Flags QueryRequest::getFlags() const
|
2013-02-02 21:52:49 +01:00
|
|
|
|
{
|
|
|
|
|
return _flags;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 19:56:32 +01:00
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
|
inline void QueryRequest::setFlags(QueryRequest::Flags flags)
|
2013-02-02 21:52:49 +01:00
|
|
|
|
{
|
|
|
|
|
_flags = flags;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 19:56:32 +01:00
|
|
|
|
|
|
|
|
|
inline std::string QueryRequest::fullCollectionName() const
|
|
|
|
|
{
|
|
|
|
|
return _fullCollectionName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-02-20 22:20:55 +01:00
|
|
|
|
inline Document& QueryRequest::selector()
|
2013-02-02 21:52:49 +01:00
|
|
|
|
{
|
2013-02-20 22:20:55 +01:00
|
|
|
|
return _selector;
|
2013-02-02 21:52:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 19:56:32 +01:00
|
|
|
|
|
2013-02-13 19:10:57 +01:00
|
|
|
|
inline Document& QueryRequest::returnFieldSelector()
|
2013-02-02 21:52:49 +01:00
|
|
|
|
{
|
|
|
|
|
return _returnFieldSelector;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 19:56:32 +01:00
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
|
inline Int32 QueryRequest::getNumberToSkip() const
|
2013-02-02 21:52:49 +01:00
|
|
|
|
{
|
|
|
|
|
return _numberToSkip;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 19:56:32 +01:00
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
|
inline void QueryRequest::setNumberToSkip(Int32 n)
|
2013-02-02 21:52:49 +01:00
|
|
|
|
{
|
|
|
|
|
_numberToSkip = n;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 19:56:32 +01:00
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
|
inline Int32 QueryRequest::getNumberToReturn() const
|
2013-02-02 21:52:49 +01:00
|
|
|
|
{
|
|
|
|
|
return _numberToReturn;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 19:56:32 +01:00
|
|
|
|
|
2013-02-15 22:32:24 +01:00
|
|
|
|
inline void QueryRequest::setNumberToReturn(Int32 n)
|
2013-02-02 21:52:49 +01:00
|
|
|
|
{
|
|
|
|
|
_numberToReturn = n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-03-12 04:49:54 +01:00
|
|
|
|
} } // namespace Poco::MongoDB
|
|
|
|
|
|
2013-02-02 21:52:49 +01:00
|
|
|
|
|
2017-02-13 15:53:08 +01:00
|
|
|
|
#endif // MongoDB_QueryRequest_INCLUDED
|