我试图编写一个连接到MongoDB并更新给定集合中特定文档的函数。更新本身按预期工作。但是,当我运行代码时,它确实在更新文档后结束。你知道为什么吗?很感谢任何形式的帮助。
function updateColletion(payload) {
mongoose.connect(process.env.MONGODB_URI, {useNewUrlParser: true},
function(err) {
if (err) throw err;
console.log('Successfully connected');
MongoDBModel.findByIdAndUpdate('exampleDocumentID', {
payload
},
{upsert: true},
function(err) {
if (err) throw err;
console.log("TrackerRegex updated.")
});
});
};
const updatePayload = {exampleKey: exampleVar};
updateTrackerRegex(updatePayload);