How to batch add to collection in angular firestore?

How to batch add to collection in angular firestore?

Following function tries to create new users inside a collection:

  batchCreate() {
    const batch = this.firestore.collection('users').ref.firestore.batch();


    this.users.forEach((user) => {
      const ref: any = this.firestore
        .collection('users')


// even if  reference a doc like this (it doesnot works):
//      const ref: any = this.firestore
//        .collection('users').doc(user.id)


//this collection and documents doesnot exists on the db.

      batch.set(ref, user);
    });

batch.commit()
  }

But the above logic is not working.

Not sure why!

The idea was to create a collection (which formally doesnot exists but created on the go), and push the whole list of users in a single transaction, instead of single post requests. Is that possible?

The idea was to bulk add or update a collection



from Recent Questions - Stack Overflow https://ift.tt/2PyF0DS
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Network Error and Timeout on Authorize.net JS

Spring Elasticsearch Operations