简体   繁体   English

在没有_id索引的有上限集合上使用MongoDB _id查询,集合的性能会很差

[英]MongoDB _id query on capped collection without an _id index, performance will be poor collection

i create a capped collection( crawl02 ) and create an index for this capped. 我创建一个上限集合( crawl02 )并为此上限创建一个索引。

> db.system.indexes.find()
{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "test.crawl02", "name" : "_id_" }

when i runing an application and query capped collection,the MongoDB Log ALWAYS output the follow log: 当我运行应用程序并查询有上限的集合时, MongoDB Log始终输出以下日志:

[conn2] warning: _id query on capped collection without an _id index, performance will be poor collection: test.crawl02 . [conn2] warning: _id query on capped collection without an _id index, performance will be poor collection: test.crawl02

my code statement to query a capped collection (c#) 我的代码语句来查询上限集合(C#)

 var cursor = this.QueueCollection    //crawl02
           .Find(Query.GT("_id", this._lastId))
           .SetFlags(QueryFlags.AwaitData |QueryFlags.TailableCursor 
                    | QueryFlags.NoCursorTimeout)
           .SetSortOrder(SortBy.Ascending("$natural"));
 return (MongoCursorEnumerator<QueueMessage<T>>)cursor.GetEnumerator();

read a message from about cursor variable: 从有关游标变量的消息中读取消息:

while(true){
   if (this._cursor.MoveNext())
      return this._currsor.Current;
   else
      return null
}

i don't understand why the mongodb waning me the crawl02 not have an index. 我不明白为什么mongodb使我的crawl02没有索引。

==================================== by update ====================================更新

ok,i found an article about Tailable Cursors at MongoDB office website ,the message is : 好的,我在MongoDB办公网站上找到了一篇有关可尾光标的文章,消息是:

Tailable cursors are only allowed on capped collections and can only return objects in natural order. Tailable queries never use indexes.

that's because mongodb log warning? 那是因为mongodb记录警告吗? Tailable queries never use indexes.??

===================update 2 sorry,i forgot the mongodb log warning is about test.crawl02,i has changed. ==================更新2抱歉,我忘记了mongodb日志警告有关test.crawl02,我已更改。

The error says you have no index on test.crawl01. 该错误表明您在test.crawl01上没有索引。 This is correct. 这是对的。 When you you do db.system.indexes.find() you have an index on the _id field on test.crawl02 not test.crawl01 Create an index on test.crawl01. 当您执行db.system.indexes.find()您在test.crawl02的_id字段上有一个索引,而不是test.crawl01的test.crawl01上创建了索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM