mongo-dart / mongo_dart

Mongo_dart: MongoDB driver for Dart programming language
https://pub.dev/packages/mongo_dart
MIT License
446 stars 98 forks source link

Can we insert doc on table A with update doc on table B at the same time? #374

Closed SittiphanSittisak closed 3 months ago

SittiphanSittisak commented 4 months ago

I want to update the doc and insert a doc with a different table and if some query is not successful, cancel it. My code sample:

    mongodb.transaction.open();
    final firstResult = await firstDbCollection.updateOne(selectorBuilder, modifierBuilder);
    final secondResult = await secondDbCollection.insertOne(map);
    firstResult.nModified == 1 || secondResult.nInserted == 1 ? mongodb.transaction.saveAndClose() : mongodb.transaction.cancelAndClose();

But this package doesn't have the transaction at this moment. So, I wonder is there any solution to update and insert with a different table at the same time(success or failure together or just do these queries at the same time)?

giorgiofran commented 4 months ago

Hi, I have no solution for that. If you want I have published a development version of a new driver mongo_db_driver that has support for transactions. If you have time to test it would be a great help!

giorgiofran commented 3 months ago

I close this issue.