I cant increment() in my firestore.d.ts file
I am on version:
- @google-cloud/[email protected]
This is the firestore.d.ts file: https://pastebin.com/eEHg83kf (i cant find increment() in there)
This is what i am trying to do: admin.firestore.FieldValue.increment(1)
This is the error i am getting on firebase cloud functions logs:
TypeError: admin.firestore.FieldValue.increment is not a function
at exports.setAvailableItemsCount.functions.firestore.document.onUpdate (/srv/index.js:203:74)
at
@momoDragon I just verified that it's showing up for me:
$ npm install firebase-admin
...
$ grep "increment(" node_modules/\@google-cloud/firestore/types/firestore.d.ts
static increment(n: number): FieldValue;
If your node_modules/\@google-cloud/firestore/types/firestore.d.ts doesn't include it, can you double check the version number at the bottom of node_modules/\@google-cloud/firestore/package.json to make sure it's 1.2.0?
@momoDragon that file you've provided looks like an older version of the firesore types, perhaps try the following:
npm uninstall @google-cloud/firestore
rm -rf node_modules/*
npm i @google-cloud/[email protected]
:point_up: let me know if this does the trick for you :+1:
rm -rf node_modules/* didnt work for me so i just manually deleted the file. And then reinstalled functions. works like a charm! thanks a million!
Souldent just by upgrading functions by npm do the job without deleting and reinstalling? Why the extra steps?
@momoDragon the extra steps should not be necessary, I'm wondering if there was something odd in your package-lock.json, which uninstalling and reinstalling would help correct.
I don't expect that you should need to do this again.
Ok my firestore.d.ts has the increment function after the reinstall of modules.
however my console log still giving me errors
TypeError: admin.firestore.FieldValue.increment is not a function
at exports.setAvailableItemsCount.functions.firestore.document.onUpdate (/srv/index.js:196:73)
at
@momoDragon could you provide some source-code, or a link to a repository that reproduces the issue? I'm curious what operation you're attempting to perform.
FieldValue I believe might be a class, so increment would be on its prototype and not exist until you new the object.
Let me know what you're trying to achieve, and I might be able to provide some sample code.
var docRef = admin.firestore().collection('vendors').doc(user.email);
docRef.update({
'availableItemsCount' : admin.firestore.FieldValue.increment(1),
});
@momoDragon I think there's just a slight misunderstanding happening here about the increment API (I've opened an issue to document it better); here's how you'd go about implementing a field:
const {Firestore, FieldValue} = require('@google-cloud/firestore');
async function main() {
const firestore = new Firestore();
const document = firestore.doc('folks/bob');
await document.set({
name: 'Bob',
age: 33,
});
console.log('Entered new data into the document');
// Update an existing document.
await document.update({
age: FieldValue.increment(33)
});
};
main().catch(console.error);
Note that I import FieldValue from the main library, and then simply call it directly: FieldValue.increment(N).
Btw my usage is for cloud functions node.js
Getting this error from your usage:
ReferenceError: FieldValue is not defined
at exports.setAvailableItemsCount.functions.firestore.document.onUpdate (/srv/index.js:196:46)
at

cc/ @hiranya911 who owns the Admin SDK and might know if there's some reason this wouldn't be working (we added FieldValue.increment() in a recent @gcloud/firestore release, but it's apparently not showing up / working via the admin SDK).
Any update on the situation?
@momoDragon This is working for me. I ran "npm install firebase-admin" and then put this in a .ts file and ran it:
import * as admin from 'firebase-admin';
admin.initializeApp({...});
const db = admin.firestore();
const doc = db.doc('foo/bar');
doc.update({count: admin.firestore.FieldValue.increment(1) }).then(() => console.log('success'));
And it printed "success" and the value was incremented. If you're still having issues, perhaps you can provide an MCVE?
@mikelehen I think the problem is that @momoDragon is using @google-cloud/firestore; it would seem that the admin functionality works as expected in the npm package firebase-admin, but not in the npm package @google-cloud/firestore.
@momoDragon perhaps you could use the firebase-admin library for the time being, and I'll work on talking to the right people to consolidate the two libraries.
@momoDragon what might be very helpful at this point to help us debug further also, would be if you could provide us with either a small GitHub repository that demonstrates your issues, or a gist.
@mikelehen and I are scratching our heads trying to figure out exactly how you're initializing your admin instance.
const admin = require('firebase-admin'); this is how i initialize
If you’re still stuck, can you provide your full code and the output of ‘npm ls’?
On Wed, Apr 10, 2019 at 9:04 PM momoDragon [email protected] wrote:
const admin = require('firebase-admin'); this is how i initialize
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/googleapis/nodejs-firestore/issues/597#issuecomment-481956896, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMmHE2sHmvOq7bYMQkmau_5OqrRTeKyks5vfrREgaJpZM4ceKl5 .
here is the code: https://pastebin.com/EQtKDQvK
error in cloud functions logs: TypeError: admin.firestore.FieldValue.increment is not a function at exports.testIncrement.functions.https.onRequest (/srv/index.js:1032:46) at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:57:9) at /worker/worker.js:783:7 at /worker/worker.js:766:11 at _combinedTickCallback (internal/process/next_tick.js:132:7) at process._tickDomainCallback (internal/process/next_tick.js:219:9)
i edited my comment link ^