Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Firestore operations not performed correctly #667

@merlinnot

Description

@merlinnot

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));

Metadata

Metadata

Labels

api: firestoreIssues related to the googleapis/nodejs-firestore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions