如何在MongoDB Shell中创建可尾游标? [英] How to create tailable cursor in MongoDB shell?

查看:54
本文介绍了如何在MongoDB Shell中创建可尾游标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想直接在MongoDB中为封顶集合创建一个无限的处理循环,但是我找不到在MongoDB shell中如何获取尾巴游标的方法.在Python中,可以使用 Collection.find()中的 tailable 选项..

I would like to create an endless processing loop for capped collection directly in MongoDB, but I can't find how I can get tailabale cursor in MongoDB shell. It's possible in Python with tailable option in Collection.find() though..

推荐答案

您可以使用addOption()在find()之后添加选项:

You can add the option after find() using addOption():

db.coll.find().addOption(2) // probably want to use 2(tailable) + 32(await_data)

在此处查看所有选项: http://www. mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-OPQUERY

See all the options here: http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-OPQUERY

您希望将其置于循环中,因为即使是可拖尾的游标(w/await_data)有时也不会返回结果.

You will want to put this in a loop as even tailable cursors (w/await_data) return no results sometimes.

这篇关于如何在MongoDB Shell中创建可尾游标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆