-
Type:
Task
-
Resolution: Works as Designed
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
pymongo version 3.12.0
I'm using watch to monitor db changes, but when a db change occur I get the error:
cursor id CURSOR_ID_NUMBER is already in use
I'm using it in Flask to stream db changes to the client side
client = MongoClient(mongo_url)
db_stream = client[DB_NAME][COLLECTION_NAME].watch([{ "$match": {'fullDocument.user_id':'{}'.format(CLIENT_ID)}}])
And in Flask:
def event_stream():
change = False
try:
change = next(db_stream)
except Exception as e:
print("change err: {}".format(str(e)))
print("db change: {}".format(change))
yield dumps(change)
@app.route('/stream')
def stream():
db_change = event_stream()
return Response('data: {}\n\n'.format(dumps(db_change)),
mimetype="text/event-stream")