Firestore Emulator doesn't handle admin.firestore.FieldValue.increment on 9.2.0
See original GitHub issue[REQUIRED] Step 2: Describe your environment
- Operating System version: Windows
- Firebase SDK version: 9.2.0
- Firebase Product: Emulator
- Node.js version: 10.15.3
- NPM version: 6.4.1
[REQUIRED] Step 3: Describe the problem
I had a function that does doc.update({field: admin.firestore.FieldValue.increment(1)})
, and a test to expect that field === 1
. It was working fine when I was on ~8.0.0
, but I tried to update to 9.2.0
, this test started to fail.
Expected: 1
Received: undefined
I wonder if admin.firestore.FieldValue.increment
is still properly handled in the emulator?
Steps to reproduce:
- Write a cloud function and a test
- Run test with it connected to emulator
Relevant Code:
Running test:
firebase emulators:exec --only firestore \"jest --config jest.config.js\"
Connecting to emulator:
const projectId = Math.random()
.toString(36)
.substring(7);
process.env.GCLOUD_PROJECT = projectId;
process.env.FIRESTORE_EMULATOR_HOST = "127.0.0.1:8080";
initializeApp({ projectId });
Code for function:
...
await db.doc(`users/${USER_ID}`).update({
// This field is undefined before
field: admin.firestore.FieldValue.increment(1)
});
...
Test:
it("successfullly marks an item as purchased if it's made by the requester and increment counter", async () => {
const wrapped = testEnv.wrap(functionName);
const data = {};
const res = await wrapped(data, {
auth: { uid: USER_ID }
});
await expect(res).resolves;
const userDoc = await db.doc(`users/${USER_ID}`).get();
expect(userDoc .data()!["field"]).toBe(1);
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Cannot get FieldValue.increment working in Firestore ...
I am using firebase-admin 8.3.0 . So I am using @firebase/testing for my mocha tests which execute against the firestore emulator which ...
Read more >Firebase Admin Node.js SDK Release Notes - Google
The Cloud Firestore API now supports the preferRest setting to force the use of REST transport until an operation requires gRPC. Cloud Messaging....
Read more >Increment a Firestore document field - Google Cloud
Atomically increment the population of the city by 50. await washingtonRef.UpdateAsync("Regions", FieldValue.Increment(50));. View on GitHub Feedback.
Read more >firebase - UNPKG
firebase/firebase-firestore-lite.js.map. Version: ... n */\n NODE_CLIENT: false,\n /**\n * @define {boolean} Whether this is the Admin Node.js SDK.
Read more >Firestore - increment a numeric value [resolved]
The Firebase Request doesn't wait for that value to be returned from the function before it makes its call. I discovered this myself...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For anyone who still has the problem and is looking for a solution. I found this answer that helped me:
https://github.com/firebase/firebase-admin-node/issues/1803#issuecomment-1179244087 https://stackoverflow.com/a/73047370/10433038
Do not use this:
use this:
@elvisun This issue is usually caused by using types from different versions of Firestore together. Can you verify that you only have a single version of
@google-cloud/firestore
(and ideally no version of@firebase/firestore
) in your dependency tree?