[DRIVERS-656] Change Transactions Examples to not drop database Created: 21/May/19  Updated: 28/Oct/23  Resolved: 30/Oct/19

Status: Closed
Project: Drivers
Component/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Alyson Cabral (Inactive) Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Driver Compliance:
Key Status/Resolution FixVersion
SWIFT-551 Done

 Description   

In sharding, dropping the database does not go through database versioning. So if you have more than 1 mongos and are round robining requests (in the way all drivers do) any mongos that did not explicitly send the drop or create will not discover that the database exists, thus sending incorrect results. For example after inserting data and then performing a count, you'll see the count is 0. See this ticket for details: HELP-9914

We're working on potential solutions on the server-side, but I want to update all the transactions examples that we'd like to reference in the general public beta.

I do not believe the node examples have this issue: https://gist.github.com/mbroadst/2a719a7adeb8b0476f50ac5643d70166

Python does: https://github.com/mongodb/mongo-python-driver/blob/3.7.0b0/test/test_examples.py#L849

Java also does: https://gist.github.com/jyemin/7031cc235759e4619ab0ab342f22db37#file-betaexamples-java-L53

Changing Java to the below works

       database = client.getDatabase("test");
        // create the collections in advance so there is no attempt to implicitly create them within the transaction
        database.createCollection("inventory");
        database.createCollection("shipment");
 
        inventory = database.getCollection("inventory");
        shipment = database.getCollection("shipment");
 
        inventory.deleteMany(new Document());
        shipment.deleteMany(new Document());



 Comments   
Comment by Alyson Cabral (Inactive) [ 21/May/19 ]

jeff.yemin shane.harvey I've confirmed with Kal that just changing the dropDatabase to dropCollection would work, even if the collection is sharded.

Generated at Thu Feb 08 08:22:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.