如何删除猫鼬中的多个ID

时间:2019-07-19 05:10:52

标签: mongoose

我要删除多个

_ids = ['123', '234', '345'];

_ids.forEach(_id => {
  await model.deleteOne({ _id });
});

有更好的方法吗?

2 个答案:

答案 0 :(得分:0)

是的,使用deleteMany的猫鼬,

_ids = ['123', '234', '345'];

model.deleteMany({_id: { $in: _ids}}, function(err) {})

答案 1 :(得分:0)

您可以从猫鼬中使用deleteMany

if (event is Login) {
  yield currentState.copyWith(formProcessing: true);
  store.dispatch(authActions.login(
    currentState.username,
    currentState.password,
    (error, data) {
      print(error);
      print(data);
      // I want to yield here.
      yield currentState.copyWith(formProcessing: false);
    },
  ));
}

否则

您同样做得很好

yield