来自MongoDB文档的一句话:db.collection.find() RETURNS A cursor to the documents that match the query criteria. When the find() method “returns documents,” the method is actually returning a cursor to the documents.
举一个例子,假设collection中的数据量很大很大,那么db.collection.find(<criteria>, limit=40)的效率和cursor = db.collection.find(<criteria>),然后for x in cursor 这种方法的效率比起来,后一种方法的效率会低么,具体的差别有多大?
实际的应用场景是通过 db.collection.find(<criteria>) 返回一个cursor,由于业务的需要,从结果集中取出的结果数量是不定的,通过迭代器选取一些结果满足需求之后就会终止迭代。
举一个例子,假设collection中的数据量很大很大,那么db.collection.find(<criteria>, limit=40)的效率和cursor = db.collection.find(<criteria>),然后for x in cursor 这种方法的效率比起来,后一种方法的效率会低么,具体的差别有多大?
实际的应用场景是通过 db.collection.find(<criteria>) 返回一个cursor,由于业务的需要,从结果集中取出的结果数量是不定的,通过迭代器选取一些结果满足需求之后就会终止迭代。
