question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Firestore operations not performed correctly

See original GitHub issue

The title might be pretty vague, but I hope the repro will help to pinpoint the issue quickly.

Environment details

  • OS: Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019
  • Node.js version: v8.16.0, v10.16.0
  • npm version: v6.4.1, v6.9.0
  • @google-cloud/firestore version: v2.0.0, v2.1.0

Steps to reproduce

Please run the following with version 2.0.0 or 2.1.0 of the library:

import { Firestore } from '@google-cloud/firestore';
import { credentials } from '@grpc/grpc-js';

const BATCH_SIZE = 16;

const firestore = new Firestore({
  port: 8080,
  projectId: 'test',
  servicePath: 'localhost',
  sslCreds: credentials.createInsecure(),
});

const collection = firestore.collection('collection');

const run = async () => {
  const batch = firestore.batch();

  for (let i = 0; i < BATCH_SIZE; ++i) {
    batch.set(collection.doc(), {});
  }

  await batch.commit();

  const snapshot = await collection.get();

  console.log(snapshot.size);
};

run().catch(x => console.error(x.message));

An expected result would be to see BATCH_SIZE (16) in the console. In reality a random number is printed.

This code runs against Firestore Emulator, but I verified it against the Cloud environment too. To run it against the cloud environment, it should be sufficient to change instantiation of the client to:

const firestore = new Firestore({ projectId: 'my-project-id' });

I verified that it does work correctly on major version 1. You can use the following code (GRPC credentials must come from grpc library, not @grpc/grpc-js:

import { Firestore } from '@google-cloud/firestore';
import { credentials } from 'grpc';

const BATCH_SIZE = 16;

const firestore = new Firestore({
  port: 8080,
  projectId: 'test',
  servicePath: 'localhost',
  sslCreds: credentials.createInsecure(),
});

const collection = firestore.collection('collection');

const run = async () => {
  const batch = firestore.batch();

  for (let i = 0; i < BATCH_SIZE; ++i) {
    batch.set(collection.doc(), {});
  }

  await batch.commit();

  const snapshot = await collection.get();

  console.log(snapshot.size);
};

run().catch(x => console.error(x.message));

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
schmidt-sebastiancommented, May 30, 2019

We published a release that pins @grpc/grpc-js to v0.4.0. If you install @google-cloud/firestore v2.1.1, your the grpc-js module should be downgraded. If you haven’t yet updated, you will also not be affected, since we un-published the affected version of grpc-js.

Thanks for reporting.

0reactions
schmidt-sebastiancommented, May 31, 2019

@opyate If you remove your node_modules folder, an npm install should get you @grpc/grpc-js@0.4.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best practices for Cloud Firestore - Firebase
Read and write operations · Avoid writing to a document more than once per second. For more information, see Updates to a single...
Read more >
Firestore Import - no error, but no changes - Stack Overflow
I've successfully completed all the "Before you begin" steps. I've exported data from one instance/project (staging) into it's bucket, and it * ...
Read more >
Transactions and batched writes | Firestore - Google Cloud
Batched writes perform better than serialized writes but not better than parallel writes. You should use a server client library for bulk data...
Read more >
Cloud Firestore: On data constraints and evolvability - Medium
But that is not entirely correct. In this article we look at Firestore's data model, the constraints we can apply on Firestore data, ......
Read more >
apiv1 - Go Packages
Package apiv1 is an auto-generated package for the Cloud Firestore API. ... If Poll succeeds and the operation has not completed, the returned...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found