Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
Should I do GeoFirestore transactions in Cloud Functions or Client-side?

I am using this library https://geofirestore.com/ to create a document in a collection if no other document already exists within the given coordinates. Now, should I use this library's method for transactions in the Cloud function or directly in the app?

I personally don't see a reason to do it in the Cloud, tho I might be wrong so I am asking for your opinion.

const geocollection = GeoFirestore.collection('chats');
const query = geocollection.limit(1).near({ center: new firebase.firestore.GeoPoint(latitude, longitude), radius: 0.03 });

GeoFirestore.runTransaction((transaction) => {
  const geotransaction = new GeoTransaction(transaction);
  return geotransaction.get(query).then((sfDoc) => {
    if (sfDoc.exists) {
      sfDoc.docs.forEach(documentSnapshot => {
        if (documentSnapshot.exists) {
          firestore().collection('chats')
            .doc(documentSnapshot.id)
            .get()
            .then((res) => {                  
                // insert new document
                geocollection.add({
                  name: 'Geofirestore',
                  uid: device_id,                     
                  coordinates: new firebase.firestore.GeoPoint(latitude, longitude),
                  created: currenttime
                })                  
            })
        }
      });
    } else {
      geocollection.add({
        name: 'Geofirestore',
        uid: device_id,           
        coordinates: new firebase.firestore.GeoPoint(latitude, longitude),
        created: currenttime
      })
    }
  });
});
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

If you want the location of the document to be unique in its collection, consider using that location as the basis for the document ID, or some value derived from the location (such as a hash, or the geohash that Geofirestore uses).

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda