次のコードがあります。
connection = MongoClient('core.mongo.com', 27017)
db = connection['admin']
first = db.oplog.rs.find().sort('$natural', pymongo.DESCENDING).limit(-1).next()
ts = first['ts']
while True:
cursor = db.oplog.find({'ts': {'$gt': ts}}, tailable=True, await_data=True)
while cursor.alive:
for doc in cursor:
ts = doc['ts']
time.sleep(1)
私は得る:
Traceback (most recent call last):
File "tail.py", line 25, in <module>
ts = first['ts']
File "/Library/Python/2.7/site-packages/pymongo/cursor.py", line 569, in __getitem__
"instances" % index)
TypeError: index 'ts' cannot be applied to Cursor instances
oplog
mongo データベースから最新のタイムスタンプを取得するにはどうすればよいですか?