【发布时间】:2021-10-07 21:22:01
【问题描述】:
我是 mongodb 的新手,我尝试使用 post 方法通过我的 html 页面将数据插入数据库。我在服务器端使用猫鼬。 这是我的代码的样子。
var LoginInfoSchema = new mongoose.Schema
({
_id : String,
user: String,
password: String
});
var user = mongoose.model('user',LoginInfoSchema);
app.post('/login', function(req, res) {
new user({
_id : req.body.email,
user : req.body.user,
password : req.body.password
}).save(function(err,doc){
if(err) res.json(err);
else res.redirect('/');
});
mongoose.connect('mongodb://localhost:27017/UserInfo',function(err,db){
if(err) console.log(err);
db.collection("users").insertOne(user, function(error, result) {
if(error) console.log(error);
console.log("1 document inserted");
db.close();
});
});
});
每当我从 localhost html 页面插入数据时,它都会成功插入,我会从 mongo.exe 终端看到它,但我得到的错误是
名称:'MongoError', 消息:'写入批量大小必须在 1 到 100000 之间。得到 0 个操作。', 好的:0, errmsg: '写入批量大小必须在 1 到 100000 之间。得到 0 个操作。', 代码:16, 代号:'无效长度', [符号(mongoErrorContextSymbol)]:{} }
我到处搜索我无法解决的问题。具体是什么意思,请回答。
【问题讨论】: