Steven Wong
Steven Wong

Reputation: 71

Cloud Functions for Firebase iterate through a child node

I just started to use firebase Functions and I am new to the node.js environment, can somebody tell how to iterate through a child node and get the child values.

Upvotes: 6

Views: 4488

Answers (2)

Diego P
Diego P

Reputation: 1758

see this example:

  const parentRef = admin.database().ref("path");
  return parentRef.once('value').then(snapshot => {
      const updates = {};
      snapshot.forEach(function(child) {
        updates[child.key] = null;
      });
      return parentRef.update(updates);
  });

Upvotes: 7

Bob Snyder
Bob Snyder

Reputation: 38299

Have you looked through the Cloud Functions for Firebase Samples? They contain many helpful examples of common operations. The code in this sample shows some of what you are looking for.

Upvotes: 2

Related Questions