繁体   English   中英

如何在 mongoose 的事务中使用 deleteMany

[英]how to use deleteMany in transaction of mongoose

我想从集合中删除一个 model 模式数组。

用于删除我使用的一个 model

    let place = await Place.findById(placeId);

    const sess = await mongoose.startSession();
    sess.startTransaction();
    await place.remove({ session: sess });// remove place
    await sess.commitTransaction();

如果place是一个数组

    let place = await Place.find({title : "Eiffel"}); // Array of Model

    const sess = await mongoose.startSession();
    sess.startTransaction();
    await place.deleteMany({ session: sess });// error ????
    await sess.commitTransaction();
await place.deleteMany({'xyz': 999}).session(sess);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM