Giter VIP home page Giter VIP logo

Comments (11)

schmidt-sebastian avatar schmidt-sebastian commented on May 30, 2024

Thanks for reporting this, I will try to push a fix for this in the next release.

from nodejs-firestore.

schmidt-sebastian avatar schmidt-sebastian commented on May 30, 2024

@rodrigoreal How are you saving the GeoPoint? As a top-level entity or within an object? We currently only support GeoPoints within a different object.

from nodejs-firestore.

rodrigoreal avatar rodrigoreal commented on May 30, 2024

@schmidt-sebastian
I'm saving it as an object on my seller entity.

const seller: SellersInterface = {
  name: body.name,
  location: new firestore.GeoPoint(lat, lng)
};
admin.firestore().collection('sellers').add(seller);
export interface SellersInterface {
  id?: string;
  name: string;
  location: firestore.GeoPoint;
}

I'm doing something wrong?

from nodejs-firestore.

schmidt-sebastian avatar schmidt-sebastian commented on May 30, 2024

The Firestore SDK can only recognize types that are part of its own namespace. Since you are using Firestore through the Admin SDK, you need to save GeoPoints as follows:

admin.firestore().collection('sellers').add({
   location:new admin.firestore.GeoPoint(1.0, 1.0)
});

I'm going to close this issue for now. If the above doesn't help, please feel free to re-open.

from nodejs-firestore.

amitransinha avatar amitransinha commented on May 30, 2024

Hi,
not able to save geo point. I am doing the same as you mentioned above but it does not help me.
Please have a look on 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

from nodejs-firestore.

schmidt-sebastian avatar schmidt-sebastian commented on May 30, 2024

@amitransinha

Where are you getting Firestore from ('db')? If I add the following, your code works:

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.

from nodejs-firestore.

amitransinha avatar amitransinha commented on May 30, 2024

@schmidt-sebastian
Thanks.. It work.

Yes, i was using the GCloud instance to save data in collection.
I am facing one more issue with firestore.
Can I fetch data from multiple collections using join? As we can do same in MySQL and MongoDB as well.

Your response will be much appreciable.

from nodejs-firestore.

schmidt-sebastian avatar schmidt-sebastian commented on May 30, 2024

We currently don't expose a join operation. If you know the keys of your data, you can use getAll() on the main Firestore class.

from nodejs-firestore.

surya-fleetrun-in avatar surya-fleetrun-in commented on May 30, 2024

When I use a google cloud function written in typescript to retrieve a document containing Geopoint, I am hitting the same issue with the response containing _latitude and _longitude for geopoint.

const Firestore = admin.firestore;
const db = Firestore();
const snap = await db
      .collection("addresses")
      .doc(docId)
      .get();
const snapdata = snap.data();
console.log(snapdata);

from nodejs-firestore.

MarkDuckworth avatar MarkDuckworth commented on May 30, 2024

@surya-fleetrun-in, when I run this code, I see this logged:

{
  point: GeoPoint {
    _latitude: 44.04818119788449,
    _longitude: -109.7278059330043
  }
}

It looks like console.log(snapdata) is logging the private properties of the GeoPoint object.

However, the returned point object is an instance of the GeoPoint class, so you should be able to use the latitude and longitude getters.

console.log(snapdata['point'].latitude);
console.log(snapdata['point'].longitude);

I tested using [email protected].

from nodejs-firestore.

surya-fleetrun-in avatar surya-fleetrun-in commented on May 30, 2024

Thanks @MarkDuckworth the postman response is also showing the private properties, which confused us a little, but the getter seems to work.

from nodejs-firestore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.