【发布时间】:2017-08-15 01:20:10
【问题描述】:
这就是我所做的
static populateReferralLinks(){
return Promise.coroutine(function*(){
let companies = yield Company.find({},'billing referral current_referral_program')
.populate('billing.user','emails name');
for(let i = 0 ; i < length ; i++){
companies[i].referral.is_created = true;
companies[i].referral.referral_email = companies[i].billing.user.emails[0].email;
companies[i] = yield companies[i].save();
}
return companies;
}).apply(this)
.catch((err) => {
throw err;
});
}
我有一个功能,我只选择 3 个字段继续进行,即计费、current_referral_program 和推荐。 并使用存储在 billing.user 中的参考填充用户。 现在当我调用这个函数时就在线了
公司[i].save();
windows 终端显示以下命令
Mongoose: companies.update(
{ _id: ObjectId("58d12e1a588a96311075c45c") },
{ '$set':
{ billing:
{ configured: false,
user: ObjectId("58d12e16588a96311075c45a") },
referral:
{ is_created: true,
referral_email: 'jadon.devesh98@gmail.com',
},
updatedAt: new Date("Wed, 22 Mar 2017 12:02:55 GMT")
}
}
)
但在 Mac 的终端中却显示了这个命令
Mongoose: companies.update({ _id: ObjectId("58d12e1a588a96311075c45c") }) { '$set': { billing: { configured: false, user: ObjectId("58d12e16588a96311075c45a") }, current_limit: {}, current_usage: {},referral: { is_created: true, referral_email: 'jadon.devesh98@gmail.com'}}, '$unset': { updatedAt: 1 } }
现在,我没有提到 current_limit 和 current_usage 为空。它在 Windows 上运行良好,但在 Mac 上将 current_limit 和 current_usage 设置为空,因此在 Mac 上使用空对象更新我的文档,但在 Windows 上没有。
它在两个操作系统上的行为方式应该相同,但事实并非如此。
【问题讨论】:
标签: mongodb mongoose mongoose-populate