【发布时间】:2020-10-27 12:18:50
【问题描述】:
所以我能够使用 nodejs / mongoDB 创建一个集合 使用此代码
// create a collection and inserting the object
dbo.collection('employees').insertOne(myobj, function(err, res) {
//if there is an error throw error message
if (err) throw err;
// print out if collection is created
console.log(colors.green("Collection created ✓"),'\n','\n',companyMotto, '-',
subDomain,'\n','\n');
//close the db
db.close();
});
我试图找出一个代码来更新整个集合,如果他们的集合已经存在使用这个
// create a collection and inserting the object
dbo.collection('employees').updateOne(myobj, function(err, res) {
//if there is an error throw error message
if (err) throw err;
// print out if collection is updated
console.log(colors.green("Collection updated ✓"),'\n','\n',companyMotto, '-',
subDomain,'\n','\n');
//close the db
db.close();
});
但我收到一个错误“...throw new TypeError('更新文档需要原子运算符');” 任何帮助将不胜感激
【问题讨论】: