Reputation: 1211
I am developing a REST api for my application in Nodejs and Express. But each time i try to send a request I get an undefined error. Please how can i enable 'ignoreundefinedproperties'
Upvotes: 58
Views: 29920
Reputation: 93
import { initializeApp } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';
initializeApp();
const db = getFirestore();
db.settings({ ignoreUndefinedProperties: true });
Inspired by other answers present here, but this one shows firebase-admin
way of doing it.
Upvotes: 3
Reputation: 11
Im using firebase-admin@^11.5.0
:
import * as admin from "firebase-admin";
import serviceAccount from "./firebase-admin-sdk.json";
const app = admin.initializeApp({
credential: admin.credential.cert(serviceAccount as admin.ServiceAccount),
databaseURL: "https://{database-id}.firebaseio.com/",
});
const firestore = app.firestore();
firestore.settings({ ignoreUndefinedProperties: true });
export firestore;
So when i import firestore, the ignoreUndefinedProperties
will set true once.
Upvotes: 0
Reputation: 15259
For anyone using the v9 API:
import { getFirestore, connectFirestoreEmulator, initializeFirestore } from 'firebase/firestore'; // Firebase v9+
// Must be called before getFirestore()
initializeFirestore(app, {
ignoreUndefinedProperties: true
});
const firestore = getFirestore(app);
Upvotes: 18
Reputation: 49460
If you're facing error (Firestore has already been initialized. You can only call settings() once) even after trying other answers, restart your IDE/VSCode and terminal. This is what worked for me.
Upvotes: 0
Reputation: 4490
If you are getting errors for calling this more than once, I recommend putting admin.firestore().settings({ignoreUndefinedProperties:true});
in the same place you have admin.initializeApp();
Here's how I did it in my Typescript project
initialize.ts:
import * as admin from 'firebase-admin';
import 'firebase-functions';
admin.initializeApp();
admin.firestore().settings({ignoreUndefinedProperties:true});
Top of index.ts:
import './initialize.ts'
Upvotes: 35
Reputation: 1964
once you import the firebase-admin sdk (in Typescript) like this
import * as firestore from "firebase-admin";
then you just need to set the setting like this :
const db = firestore.firestore();
db.settings({ ignoreUndefinedProperties: true })
Upvotes: 114