Added tailable_cursor and await_data query options to OP_QUERY
This commit is contained in:
@@ -23,6 +23,10 @@ from asyncio_mongo.log import logger
|
|||||||
|
|
||||||
_ONE = b"\x01\x00\x00\x00"
|
_ONE = b"\x01\x00\x00\x00"
|
||||||
_ZERO = b"\x00\x00\x00\x00"
|
_ZERO = b"\x00\x00\x00\x00"
|
||||||
|
_QUERY_OPTIONS = {
|
||||||
|
"tailable_cursor": 2,
|
||||||
|
"oplog_replay": 8,
|
||||||
|
"await_data": 32}
|
||||||
|
|
||||||
"""Low level connection to Mongo."""
|
"""Low level connection to Mongo."""
|
||||||
|
|
||||||
@@ -163,14 +167,22 @@ class MongoProtocol(asyncio.Protocol):
|
|||||||
message = struct.pack("<iq", limit, cursor_id)
|
message = struct.pack("<iq", limit, cursor_id)
|
||||||
self.send_message(2005, collection, message)
|
self.send_message(2005, collection, message)
|
||||||
|
|
||||||
def OP_QUERY(self, collection, spec, skip, limit, fields=None):
|
def OP_QUERY(self, collection, spec, skip, limit, fields=None,
|
||||||
|
tailable=False, await_data=False):
|
||||||
message = struct.pack("<ii", skip, limit) + bson.BSON.encode(spec)
|
message = struct.pack("<ii", skip, limit) + bson.BSON.encode(spec)
|
||||||
if fields:
|
if fields:
|
||||||
message += bson.BSON.encode(fields)
|
message += bson.BSON.encode(fields)
|
||||||
|
|
||||||
|
query_opts = 0
|
||||||
|
if tailable:
|
||||||
|
query_opts |= _QUERY_OPTIONS["tailable_cursor"]
|
||||||
|
if tailable and await_data:
|
||||||
|
query_opts |= _QUERY_OPTIONS["await_data"]
|
||||||
|
query_opts = struct.pack("<i", query_opts)
|
||||||
|
|
||||||
query = _MongoQuery(self.__id, collection, limit)
|
query = _MongoQuery(self.__id, collection, limit)
|
||||||
self.__queries[self.__id] = query
|
self.__queries[self.__id] = query
|
||||||
self.send_message(2004, collection, message)
|
self.send_message(2004, collection, message, query_opts)
|
||||||
return query.future
|
return query.future
|
||||||
|
|
||||||
def query_failure(self, request_id, cursor_id, response, raw_error):
|
def query_failure(self, request_id, cursor_id, response, raw_error):
|
||||||
|
|||||||
Reference in New Issue
Block a user