如何在猫鼬无条件的情况下更新多个文档?

时间:2019-05-15 21:33:55

标签: node.js mongodb mongoose

如何在猫鼬中像这样无条件地更新多个文档? 有可能吗?

运行此代码后,没有任何变化。

  const schema = new mongoose.Schema({ name: { type: String, unique: true } });
  const Customer = mongoose.model('Customer', schema);

  await new Customer({ name: 'john', profile: { age: 23 } }).save();
  await new Customer({ name: 'jack', profile: { age: 33 } }).save();

  let customers = await Customer.find();

  console.log({ customers });

  customers[0].profile.age = 20;

  const y = await Customer.updateMany(customers);

  console.log({ y });

0 个答案:

没有答案