I am unable to retrieve data from my Firestore database using Geofirestore within an Express application

I implemented a query in Express to retrieve my data. Below is the code for my Express function:

app.get('/locatii', (req, res) => {
    const geofirestore = new GeoFirestore(db);
    const geocollection = geofirestore.collection('locatii2');
    const query = geocollection.near({
        center: new firebase.firestore.GeoPoint(45.831922, 27.431149),
        radius: 3000
    });
    query.get().then(snap => {
        console.log(snap.docs())
        let places = [];
        snap.forEach(doc => {
            places.push(doc.data());
            console.log(doc.data())
        });
        res.json(places);
    })
        .catch(err => res.send(err));
});

Here is the structure of my Firestore database: https://i.sstatic.net/VgMML.png. However, when I access my endpoint, it does not display any data in the console or in Postman. I am unsure of what I missed. Thank you!

Answer №1

It appears that your data structure is missing a geohash field, which is necessary for querying documents based on their location.

In the example app provided with GeoFirestoreJS, you can extract the geohash using this code snippet:

location.lat = ...
location.lng = ...
const hash = geokit.Geokit.hash(location);

Once you have obtained the geohash, you can update your Firestore document by setting it like this:

documentRef.update(hash);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The current state of my DOM doesn't match the updated value in my model. The update is triggered by a function that is called when a button is clicked

app.controller('thumbnailController', function ($scope) { debugger $scope.customers = [ { name: 'Ave Jones', city: 'Phoenix' }, { name: 'Amie Riley', city: 'Phoenix&ap ...

Is it possible to retrieve 2 arguments within a function in a non-sequential manner?

Let's say there is a function with arguments A, B, C, D, and E. Function(A, B, C, D, E) However, not all arguments are needed all the time. For instance, only A and C are needed in some cases. Currently, I would have to call the function like this: Fu ...

Jquery slide animation not functioning properly

Hello, I am attempting to create a sliding effect for specific text where the slide effect adds something similar to extra spacing. The desired effect can be seen here: like margin or something, the framework being used is . My question is: Is there a wa ...

Error in Controller Due to Unassigned Variable ($scope Problem)

Can anyone explain why $scope.gotData is not accessible outside of the getData.success() call in the following AngularJS code? Although I can see the value of scope.gotData displayed in my view using {{gotData}} in my index.html, I'm unable to use $sc ...

Having difficulty displaying a partial view within a view while making an AJAX call

Trying to figure out what's missing in my code. I have a view with some radio buttons and I want to display a different partial view when a radio button is selected. Here's the snippet of my code: Controller public ActionResult Method(string va ...

Is there a way to keep a label in a Material-UI TextField from getting obscured by an adornment when the input is not in focus?

Here is the code for my custom TextField component: <TextField fullWidth: true, classes, helperText: errorText, FormHelperTextProps: getInputProps({ error }), InputProps: getInputProps({ error, endAdornment: error ? <Warning ...

Angular formly - Enhancing User Input Focus

I have created a field wrapper that converts normal text into an input when hovered over with the mouse. Additionally, I have a directive that sets focus on the field when it is activated. Now, I am looking for a solution where the field remains open as l ...

Find similarities between 2 observable arrays and store them in a new array using knockout data binding

There are three observable arrays set up as follows: a [1,3] b [ {"ID": 1, "Val": "Value1"}, {"ID":2, "Val":"Value2"}, {"ID":3, "Val":"Value3"}] c [] The goal is to compare array a with the IDs of elements in array b and then push the entire value of arr ...

Manipulating arrays of objects using JavaScript

I am working with an array of objects represented as follows. data: [ {col: ['amb', 1, 2],} , {col: ['bfg', 3, 4], },] My goal is to transform this data into an array of arrays like the one shown below. [ [{a: 'amb',b: [1], c ...

Wheel of fortune - The chosen option does not align with the indicator

I am looking to create a game similar to a "Spinning Wheel" where users can select three possible outcomes and then spin the wheel. If any of the chosen three options appears when the wheel stops, the user wins. In the demo provided below, you may notice ...

Enhancing a custom component with a transition-group component

I have a unique component that needs to include a list using v-for beneath it. <rearrangeable> <div v-for="item in items">...</div> </rearrangeable> I'm attempting to incorporate a <transition-group> element for addi ...

having difficulty with executing ajax post within a JavaScript function

While working on my project, I encountered a small issue. I am able to read the HTML image value and pass it to a JavaScript method successfully. However, when trying to pass this value via AJAX POST to the controller, an unexpected error occurs. The con ...

Issue with shopify-api-node: promise not returning value

Configuring a node.js app to fetch order information from Shopify. I'm attempting to save that data and execute some operations, but I'm encountering difficulties. THIS FUNCTIONALITY FUNCTIONS: shopify.order.list() .then(function(orders){ ...

A step-by-step guide on incorporating universal CSRF tokens using JQuery AJAX

As part of my development work, I am in the process of creating jquery code that communicates with the server through ajax to input data into a database based on specific request parameters. My main concern at this point is the vulnerability to CSRF attac ...

Delay the page briefly before redirecting

I want to implement a feature on my WordPress website where after successfully submitting a form, the visitor is shown a message like 'form submitted successfully' for a few seconds before being redirected back to the page they were on. The redir ...

Using Vue and Vuex to wait for asynchronous dispatch in the created hook

I'm struggling to implement asynchronous functionality for a function that retrieves data from Firebase: Upon component creation, I currently have the following: created(){ this.$store.dispatch("fetchSections"); } The Vuex action looks ...

Display various components using a dropdown selection

I am seeking guidance on how to display different components based on the selected option. I am unsure of how to write the code for displaying either component one or two. Can you provide any examples or references that may help? <template> <div ...

What sets apart Import { module } from lib and import module from lib/module in JavaScript?

I'm currently working on optimizing my vendor bundle.js file, which has gotten quite large due to my use of the material-ui library. import Card from 'material-ui'; // This is not ideal as it imports everything Could someone please explai ...

Automate logging in and out of Gmail chat by programmatically simulating clicks on the span elements that represent the chat status in Gmail

When I'm at work, I prefer using Gmail's encrypted chat feature because it logs chats without saving anything to the hard drive. However, when I'm at home, I switch to Pidgin as logging into Gmail chat at home can lead to messages ending up ...

Easy Endless Scrolling in a container (React)

My goal is to display an array of elements within a div that has a fixed height of 150px and includes an infinite scroll feature. I have explored the use of Intersection Observer, but found it too complex for my simple requirements. The items in the array ...