Tailing a collection before it is created

不羁的心 提交于 2019-12-12 03:29:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!