-
Notifications
You must be signed in to change notification settings - Fork 989
Closed
Description
[REQUIRED] Describe your environment
- Operating System version: Windows WSL2 (but all)
- Browser version: Any (also node)
- Firebase SDK version: Reproduced in 9.13.0, 9.10.x
- Firebase Product: firestore
[REQUIRED] Describe the problem
After writing a document via setDoc(ref, data, { merge: true }), if a write is pending, getDoc will return only the updated fields from the merge, not including any existing data for that document.
Steps to reproduce:
- Write an update to a document with
setDocand{ merge: true }, don't await the write. - Read the same document immediately.
- Only the updated fields will be returned.
Relevant Code:
const { disableNetwork, getFirestore, getDoc, setDoc, doc } = require('firebase/firestore');
const config = {
"firestoreEmulatorPort": 9098,
"firebase": {
"projectId": "<<insert>>",
"apiKey": "<<insert>>",
"appId": "<<insert>>",
}
}
const app = initializeApp(config.firebase);
const db = getFirestore(app);
async function run () {
// Consistent write to server
await setDoc(doc(db, "test/foo"), {
first: "Ada",
last: "Lovelace",
born: 1815
});
// Get from server
const snapshot1 = await getDoc(doc(db, "test/foo"));
console.log(snapshot1.metadata); // SnapshotMetadata { hasPendingWrites: false, fromCache: false }
console.log(snapshot1.data()); // { last: 'Lovelace', born: 1815, first: 'Ada' }
// Force opperations against the local cache.
await disableNetwork(db);
// Write to cache
const write = setDoc(doc(db, "test/foo"), {
foo: "bar"
}, { merge: true });
// Get from cache while the write is pending
const snapshot2 = await getDoc(doc(db, "test/foo"));
console.log(snapshot2.metadata); // SnapshotMetadata { hasPendingWrites: true, fromCache: true }
console.log(snapshot2.data()); // returns { foo: 'bar' } -- Expected to return { last: 'Lovelace', born: 1815, first: 'Ada', foo: 'bar' }
}
run();
dh-g-l-f, AlaricBaraou, simbrams and gligorevic