简体   繁体   English

计算mongoDB集合/数据库中的总项目

[英]Count total items in mongoDB collection/database

I can't seem to find the answer to this. 我似乎找不到答案。 I wan't a simple return statement of the amount (total) items in my collections. 我不会简单说明集合中的项目(总数)的返回值。

var mongojs = require('mongojs');
var db = mongojs("myadb",['myadb']);
db.myadb.count(function(used,a){
    console.log(used,a);
});

Null is return. Null是返回。 I'm using a mongodb JS library for node and yes, there is records in the database (12) 我正在为节点使用mongodb JS库,是的,数据库中有记录(12)

The documentation states that: 该文档指出:

cursor.count(callback)

Thanks. 谢谢。

db.collection.count({},(err, data) => {
  console.log('err ', err, 'data ', data);
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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