googleapis / nodejs-firestore

Node.js client for Google Cloud Firestore: a NoSQL document database built for automatic scaling, high performance, and ease of application development.
https://cloud.google.com/firestore/
Apache License 2.0
642 stars 149 forks source link

How to save geo point in firestore document #55

Closed amitransinha closed 7 years ago

amitransinha commented 7 years ago

Hi, I am not able to save geo point in the same format as it seen after saving it manually in the firestore document. Please have a look at my code.


const admin = require("firebase-admin"); const serviceAccount = require(process.env.FBASE_AUTH_FILE); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), databaseURL: process.env.dbURL }); let d = new Date(); let data = { name: 'Amit', location: new admin.firestore.GeoPoint(28.52038,77.28073), created_at: d.getTime() } setDoc = db.collection('users').doc().set(data); if (setDoc) { console.log('User added'); }

// Error which I am receiving is as follows. Error: Cannot encode type ([object Object]) to a Firestore Value

schmidt-sebastian commented 7 years ago

Please make sure to use the Admin Firestore types directly:

const Firestore = admin.firestore;
const db = Firestore();

At the moment, you can't mix and match the instances returned from GCloud and the Firebase Admin SDK.