Firestore operations not performed correctly
See original GitHub issueThe 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:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
@opyate If you remove your node_modules folder, an
npm install
should get you@grpc/grpc-js@0.4.0
.