问题
I'm developing an application where data is inserted into a capped collection via mongoose in Node.js and is tailed by pymongo in a Python program. I'm having a small issue where mongoose doesn't create the collection until a document is inserted into it.
In Node.js I attempt to create the collection like so:
var MyModel = mongoose.model('mymodel', mymodelSchema);
In my pymongo program I want to tail MyModel so I do this:
mymodels = db.mymodels.find(cursor_type=CursorType.TAILABLE_AWAIT)
The issue here is that if this line is called before a single entry is inserted into the mymodels collection nothing happens when I do this:
for model in mymodels:
# nothing happens
I want to start my Python program to watch for new documents - before the Node.js server starts accepting new documents. However, until a single document is inserted, the Python program won't work.
来源:https://stackoverflow.com/questions/36687627/tailing-a-collection-before-it-is-created