2010-11-19 9 views

答えて

2

これらは同じです。 MongoDBは、すべてのクエリパラメータを単一のオブジェクトとして扱います。この場合、countはサーバー側で実行される 'カーソルメソッド'です。参照してください:ここではhttp://www.mongodb.org/display/DOCS/Querying

+0

うんであることを確認することができ、彼らは同じ。これは、カーソル上の便利なメソッドです。 –

6

はMongoDBのコマンドは、ボンネットの下に何を参照するには少しトリックです:

> 
> db.mydb.count 
function (x) { 
    return this.find(x).count(); 
} 
> 
> db.mydb.find().count 
function (applySkipLimit) { 
    var cmd = {count:this._collection.getName()}; 
    if (this._query) { 
     if (this._special) { 
      cmd.query = this._query.query; 
     } else { 
      cmd.query = this._query; 
     } 
    } 
    cmd.fields = this._fields || {}; 
    if (applySkipLimit) { 
     if (this._limit) { 
      cmd.limit = this._limit; 
     } 
     if (this._skip) { 
      cmd.skip = this._skip; 
     } 
    } 
    var res = this._db.runCommand(cmd); 
    if (res && res.n != null) { 
     return res.n; 
    } 
    throw "count failed: " + tojson(res); 
} 

そうです、あなたはcollection.countは単なるラッパーの周りcollection.find().count

関連する問題