我有检索 Mongoose 对象的代码,然后使用stripeCustomerId
(存储在文档中)检索 Stripecustomer
对象(通过 nodejs 条带)。然后我想将条纹customer
对象附加到我的 Mongoose 对象上。
exports.getPlatformByCId = (cId) => {
return new Promise((resolve, reject) => {
Platform.find({ clientId: cId }).then(response => {
let user = response[0];
stripe.customers.retrieve(user.stripeCustomerId, (err, stripeCust) => {
if(err) {
user["stripeCustomer"] = null;
} else {
user["stripeCustomer"] = stripeCust;
}
resolve(user);
})
}).catch(err => {
if(err) {
if(err.error !== 'not_found') {
resolve(err);
} else {
reject(err);
}
}
})
})
}
我还尝试user.stripeCustomer = stripeCust
将猫鼬对象放回需要去的地方,但stripeCustomer
不是该对象的一部分!我已经证实,stripeCust
事实上,它返回了我期望的数据。
有什么指导吗?我想知道 Schema 是否受到某种保护,也许有一种猫鼬方法可以解决这个问题?