Skip to content

Instantly share code, notes, and snippets.

@izshreyansh
Created August 1, 2020 16:18
Show Gist options
  • Save izshreyansh/ff7d2970fe78e683f2ef17f842491fb7 to your computer and use it in GitHub Desktop.
Save izshreyansh/ff7d2970fe78e683f2ef17f842491fb7 to your computer and use it in GitHub Desktop.
firestore Sharding in vue
createCounter: function (ref, num_shards) {
let batch = db.batch();
// Initialize the counter document
batch.set(ref, { num_shards: num_shards });
// Initialize each shard with count=0
for (let i = 0; i < num_shards; i++) {
let shardRef = ref.collection('shards').doc(i.toString());
batch.set(shardRef, { count: 0 });
}
// Commit the write batch
return batch.commit();
}
this.createCounter(db.collection('shards').doc(),20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment