简体   繁体   中英

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.

> 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:

[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#)

 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.

==================================== by update

ok,i found an article about Tailable Cursors at MongoDB office website ,the message is :

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? Tailable queries never use indexes.??

===================update 2 sorry,i forgot the mongodb log warning is about test.crawl02,i has changed.

The error says you have no index on 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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