为什么我不能使用 db.collection.countDocuments()
我想获取“图像”集合中的文档数量。
我的代码
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var app = express();
app.set('view engine', 'ejs');
app.use(express.static(__dirname+'/public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
dburl = "mongodb+srv://...";
mongoose.connect(dburl);
var db = mongoose.connection;
//...
var imageSchema = mongoose.Schema({
image_name:{type:String, required:true, unique:true}
});
var Image = mongoose.model('image', imageSchema);
var Dcount = db.image.countDocuments({});
只是控制台: 在此处输入图片说明
I want to get the number of documents in the 'image' collection.
my code is
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var app = express();
app.set('view engine', 'ejs');
app.use(express.static(__dirname+'/public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
dburl = "mongodb+srv://...";
mongoose.connect(dburl);
var db = mongoose.connection;
//...
var imageSchema = mongoose.Schema({
image_name:{type:String, required:true, unique:true}
});
var Image = mongoose.model('image', imageSchema);
var Dcount = db.image.countDocuments({});
but the console :
enter image description here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
countDocuments()
可直接在模型上使用您应该执行
Image.countDocuments()
countDocuments()
is available directly on modelYou should be doing
Image.countDocuments()