以下に表示されるスキーマとMongoDBシェルバージョンを考えると:2.0.4:
インプレッション配列内のアイテムの数をカウントするにはどうすればよいですか?
Map Reduceを実行する必要があると考えていますが、これは少し複雑に思えますが、count関数で実行できると思いました。
誰かがこれを実証できますか?
1 に答える
1
A simple example of counting is:
var count = 0;
db.engagement.find({company_name: "me"},{impressions:1}).forEach(
function (doc) {
count += doc.impressions.length;
}
)
print("Impressions: " + count);
If you have a large number of documents to process, you would be better maintaining the count as an explicit field. You could either update the count when pushing to the impressions array, or use an incremental MapReduce to re-count for updated documents as needed.
于 2012-09-30T23:56:27.203 に答える