【问题标题】:Mongoose select,populate and save behaving differently on Mac and WindowsMongoose 在 Mac 和 Windows 上的选择、填充和保存行为不同
【发布时间】: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_limitcurrent_usage 为空。它在 Windows 上运行良好,但在 Mac 上将 current_limitcurrent_usage 设置为空,因此在 Mac 上使用空对象更新我的文档,但在 Windows 上没有。

它在两个操作系统上的行为方式应该相同,但事实并非如此。

【问题讨论】:

    标签: mongodb mongoose mongoose-populate


    【解决方案1】:

    显然这个问题存在于 Mongoose 4.5.8 中,并在最新版本中得到解决,即 4.9.1 Check it here

    【讨论】:

      猜你喜欢
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 2020-07-23
      • 2013-10-02
      • 2014-02-07
      • 2021-11-17
      • 2018-12-06
      • 2012-11-23
      相关资源
      最近更新 更多