Skip to content

Firestore Transaction get() returning QuerySnapshot but it should be DocumentSnapshot #344

@Rubenazo

Description

@Rubenazo

Environment

  • Operating System version: Windows 7
  • Firebase SDK version: 4.2.0
  • Library version: 6.0.0
  • Firebase Product: firestore

The problem

I'm trying to reproduce a firestore transaction with this sample code from the firebase documentation https://firebase.google.com/docs/firestore/manage-data/transactions?hl=es-419

// Initialize document
var cityRef = db.collection('cities').doc('SF');
var setCity = cityRef.set({
  name: 'San Francisco',
  state: 'CA',
  country: 'USA',
  capital: false,
  population: 860000
});

var transaction = db.runTransaction(t => {
  return t.get(cityRef)
      .then(doc => {
        // Add one person to the city population
        var newPopulation = doc.data().population + 1;
        t.update(cityRef, { population: newPopulation });
      });
}).then(result => {
  console.log('Transaction success!');
}).catch(err => {
  console.log('Transaction failure:', err);
});

However in db.runTransaction(t => { return t.get(cityRef).then(doc => { ... } ... it is say that doc must return a DocumentSnapshot, but it returns a QuerySnapshot. Even that way i can't obtain the DocumentSnapshot from doc, so there is a problem with the documentation and i'm not sure if there is also a bug with the return value.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions