Filter array of objects having array of objects
Javascript , Requests , Typescript / March 20, 2019

Q: How to filter an array of objects having an array of objects Example object –

  A  –  When we consider the above object having an array of superheroes in members. Each superhero having an array of power. We need to get the superhero having the power 4/shield  in their power array, in this case We apply the filter function on the members array, then we apply filter function on powers array present in every item in the members array in the following way.

Gives output

On applying the filter function on inner powers array, if we get the length of the resulting array greater than 0, it means that the inner array contains the power4/shiled .  

Batch add to Google Cloud Firestore database collection : Node.js and Express
databases , Express.js , Node.js / March 17, 2019

STEP 1 – InitializeFirestore App To initializeFirestore, get the key file from your Google cloud console and save it in a folder. Install the Firebase admin module

Now to initialize app, use the following code

STEP 2 Create the  reference to the collection in which you are going to add the batch data

STEP 3 Post batch data as an array to the Express server you have created.

STEP 4 Loop over the req.body using forEach and set each data to be added into the collection using the set method

Commit the data and save the data to the collection using the commit method and on success, send a success response. The full code is as follows

 

Share this page in social media platforms