失去连接后 MongoDB 从当前位置继续
您好,我在与我的 MongoDB 保持连接时遇到问题,当它失去连接时,它最终会中断我的程序,我将如何继续从我失去连接的最后一个位置进行打印,我保留了索引的计数,但是如何做我使用该计数从光标中的该位置开始
using (server.RequestStart(db))
{
var cursor = col.FindAll();
foreach (var item in cursor)
{
//code here
}
}
Hi I am having trouble keeping connection with my MongoDB and it ends up interrupting my program when it loses connection, how would I go about continuing to print from the last place that I lost connection at, I keep a count of the index but how do I use that count to start from that position in the cursor
using (server.RequestStart(db))
{
var cursor = col.FindAll();
foreach (var item in cursor)
{
//code here
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么无法保持与 MongoDB 的连接打开?您是否在查询过程中失去了网络连接?你超时了吗?
一般来说,可靠地重新启动查询的唯一方法是对结果进行排序,并且在重新启动时使用查询来跳过已处理的文档(换句话说,跳过排序键小于或等于的文档)最后处理的文档)。
您可能不需要调用 RequestStart。唯一需要调用 RequestStart 的情况是,如果您想要确保一系列数据库操作全部发生在同一个连接上(仅在异常情况下才需要)。
Why are you having trouble keeping your connection to MongoDB open? Are you losing your network connection in the middle of the query? Are you timing out?
In general the only way to reliably restart a query is if the results are sorted and you use a query on the restart to skip over documents you already processed (in other words, skip over those documents where the sort key is less than or equal to the last document processed).
You probably don't need to call RequestStart. The only time you ever need to call RequestStart is if you want to ensure that a sequence of database operations all occur on the same connection (which is only needed in unusual circumstances).