[英]MongoDB: Server has startup warnings ''Access control is not enabled for the database''
[英]Access control is not enabled for the database
我正在nodejs + express + mongodb中创建一个示例库应用程序。 当我运行gulp serve命令时,服务器完美启动。 当我转到特定的mongodb页面时,它给出错误insertMany不是函数。
var express = require('express');
var adminRouter = express.Router();
var mongodb = require('mongodb').MongoClient;
var books = [
{
title: 'world',
genre: 'Lorem Ipsum text changing occured',
author: 'Rakesh',
read: false
},
{
title: 'Make of the world',
genre: 'Digital India towards occured',
author: 'Jumanji',
read: false
}
];
var router = function (nav) {
adminRouter.route('/addBooks')
.get(function (req, res) {
var url = 'mongodb://127.0.0.1:27017/admin';
mongodb.connect(url, function (err, db) {
var collections = db.collections('books');
collections.insertMany(books,
function (err, results) {
res.send(results);
db.close();
}
);
});
});
return adminRouter;
};
module.exports = router;
行var collections = db.collections('books');
中的语法有错别字var collections = db.collections('books');
。 节点mongo驱动程序只能解释db.collection()函数,而不能解释db.collections()函数,而这实际上在语法上是错误的。
使用db.collection('books')
代替db.collections('books')
,这应该可以修复该错误。 试试看,让我知道
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.