私はmongodbを初めて使用します。コレクションにチェックインする必要があり、gameDate =現在の日付のアイテムの数を確認する必要があるシナリオがあります。私はノードjsで次のクエリを使用しています。
const count = this.games.find({gameDate:currentDate}).count();
console.log(count + "items present")
データベースに一致するレコードが1つあります。しかし、カウントを取得する代わりに、コンソールで次のエラーが発生します。
function(filter, callback) {
this.op = 'count';
if (typeof filter === 'function') {
callback = filter;
filter = undefined;
}
filter = utils.toObject(filter);
if (mquery.canMerge(filter)) {
this.merge(filter);
}
if (!callback) {
return this;
}
this.exec(callback);
return this;
}
ここでカウントを取得するにはどうすればよいですか。
countDocuments
機能を試すことができます。
games.countDocuments({gameDate:currentDate}, function (err, count) {
if (err){
console.log(err)
}else{
console.log("Total:", count)
}
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加