[英]MongoInvalidArgumentError: Selector must be a valid JavaScript object
I have documents in my monogodb consists of username, password and array and the functionality of this method that it takes some sort of string and put it in the array using the session.username我的 monogodb 中有包含用户名、密码和数组的文档以及此方法的功能,它采用某种字符串并使用 session.username 将其放入数组中
however whenever I try to call it and run it it gives me但是每当我尝试调用它并运行它时,它都会给我
MongoInvalidArgumentError: Selector must be a valid JavaScript object
exactly on line db.updateOne(.........正好在线 db.updateOne(.........
MongoClient.connect("mongodb://127.0.0.1:27017", function (err, client) {
let db = client.db('MyDB').collection('FirstCollection');
let username = req.session.username;
db.findOne({username: username},function(err,result){ const list = result.list;
let found = false;
for (let i = 0; i < list.length; i++) {
if (list[i] == destination) {
found = true;
}
}
if (found) {
alert("already on your want to go list!");
} else {
alert("added successfully");
list.push(destination);
db.updateOne(username, {$set: {list: list}}, function (err, res) {
if (err) throw err;
});
}
});});
I've tried to use update instead of updateOne and tried to create and new array update it and push it instead of the old one.我尝试使用更新而不是 updateOne 并尝试创建和新数组更新它并推送它而不是旧数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.