Created
August 1, 2020 16:18
-
-
Save izshreyansh/ff7d2970fe78e683f2ef17f842491fb7 to your computer and use it in GitHub Desktop.
firestore Sharding in vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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