【发布时间】:2020-05-31 22:24:25
【问题描述】:
编写了一个触发器函数,当listingsAndReviews 集合中有插入时,它会将完整文档插入我的集合new_list。
exports = function(changeEvent) {
const fullDocument = changeEvent.fullDocument;
const collection = context.services.get('Cluster0').db("sample_airbnb").collection("new_list");
return collection.insertMany([fullDocument])
.then(result => {
console.log(`Successfully inserted ${result.insertedIds.length} items!`);
return result;
})
.catch(err => console.error(`Failed to insert documents: ${err}`));
};
有没有办法在将数据插入 new_list 集合时只选择特定的必需列。 在这种情况下,我只需要插入 name 和 cart_id 并忽略其他。
我的样本收集列名称:
name - string
cart_id - objectid
number - string
address - string
【问题讨论】:
标签: node.js mongodb triggers database-trigger mongodb-atlas