我创建了一个50米默认大小的上限集合。最近,我注意到,当有上限的集合存储大小超过50M时,我会得到一个Cursor not found错误。我不知道是什么原因造成了这种情况:在有上限的集合大小小于默认的最大大小之前,我从来没有得到过这个错误。
if (this._cursor == null || this._cursor.IsDead)
{
var cursor = this._queueCollection.Find(Query.GT("_id", this._lastId))
.SetFlags(QueryFlags.AwaitData |
QueryFlags.TailableCursor |
QueryFlags.NoCursorTimeout)
.SetSortOrder(SortBy.Ascending("$natural"));
this._cursor =(MongoCursorEnumerator<QueueMessage<T>>)cursor.GetEnumerator();
}
try
{
if (this._cursor.MoveNext())
//do some things
return this._cursor.Current;
else
{
if (this._cursor.IsDead){
this._cursor.Dispose();
this._cursor=null;
}
}
return null;
}
catch{}this._cursor.MoveNext()将抛出一个cursor not found异常(有时,并不总是抛出)。我的代码错了吗?
发布于 2013-05-27 02:58:11
我已经找到了造成这个错误的原因。
可跟踪游标可能会死,或者无效,如果:
来自mongodb官方网站关于创建可裁剪游标(http://docs.mongodb.org/manual/tutorial/create-tailable-cursor/)的参考
在我的应用程序中,当抛出“游标未找到”异常时,总是因为游标在集合的“末尾”返回文档,然后应用程序删除这些文档。
发布于 2013-05-16 07:31:46
您可以使用foreach
var query1 = new QueryBuilder<Message>().GT(m => m.date, lastTransferredMessageDate);
var result = messagesCollection.FindAs<Message>(query1).SetFlags(QueryFlags.NoCursorTimeout);
foreach (var message in result)
{
// Your code
}https://stackoverflow.com/questions/16121796
复制相似问题