Skip to content

Instantly share code, notes, and snippets.

@kertpjatkin
Last active August 8, 2022 22:47
Show Gist options
  • Select an option

  • Save kertpjatkin/77056571b05a3ad891a30f4740e418c3 to your computer and use it in GitHub Desktop.

Select an option

Save kertpjatkin/77056571b05a3ad891a30f4740e418c3 to your computer and use it in GitHub Desktop.
async function main() {
await client.connect();
const db = client.db(dbName);
const collection = db.collection('testCollection');
const session = client.startSession({ causalConsistency: true });
const newDocument = await collection.insertOne({}, { session, writeConcern: { w: "majority" } });
const foundDocument = await collection.findOne(
{_id: newDocument.insertedId},
{ session, readConcern: "majority" }
);
console.log(foundDocument);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment