Consistency and timing
Writes
Section titled “Writes”- Your write is checked and applied to the database’s working copy on the server.
- It is written to a durable log, and then acknowledged.
- It is saved to the file in your Google Drive within about 2 seconds, together with any other writes from those seconds.
An acknowledged write is safe even if the server restarts before step 3: the log is replayed. If Google Drive is unreachable for a while, writes stay in the log and are saved when it’s back.
To wait until a write is in Drive, ask for it:
await clients.insertOne(doc, { writeConcern: { w: 'drive' } });Reads are answered from the working copy, which includes every acknowledged API write at once (read-your-writes). Before answering, the server checks Drive for edits made in the app, at most every 5 seconds.
{ readConcern: 'local' } skips that check for faster reads that may be a few seconds behind
the app (never more than a minute).
The app and the API together
Section titled “The app and the API together”| Change made… | Seen by… | When |
|---|---|---|
| through the API | the API | immediately |
| through the API | people in the app | within about 15 seconds (see below) |
| in the app | the API | within about 5 seconds after the app saves it |
An app that has the database open checks Drive every 15 seconds for an hour after an API write. If it was already open before the first API write, it notices that write at its next regular check (up to 2 minutes); Sync now in the app checks at once.
Changes merge field by field: if your code updates status while someone edits company
of the same record in the app, both changes are kept. If both change the same field at
nearly the same moment, the later change wins.
Atomicity
Section titled “Atomicity”- Every single call is atomic.
insertMany,updateMany,deleteManyandbulkWriteapply all their changes or none (for example when one document fails validation or breaks a unique field). - Calls are applied one at a time per database, so
$incnever loses an increment and unique fields hold, for all connection strings created by the same Google account. - There are no multi-call transactions. Use
bulkWriteto change several documents together, orfindOneAndUpdateto read and change one document in a single step.
Connection strings created by different Google accounts (for example teammates on a shared
database) each get their own working copy. Their writes merge like edits from two devices,
so unique fields and $inc are only guaranteed within each account’s connection strings.
Made by Faeiz Furqan