Firebase Functions Realtime Database converting array to objects problem

Viewed 30

When i try add new data to firebase realtime database its converting my array to objects. Example:

"POINTS": [{
  "w":237.00004067230424,
  "x":0,
  "y":0,
  "h":8.996961455599944
},
{
  "w":68.00003035736216,
  "h":243.99697579886254,
  "x":237,
  "y":9
}]

in Realtime Database:

"POINTS":{
  "0":{
    "h":0.9969740288429421,
    "w":96.00002364349457,
    "x":0,
    "y":0
  },
  "1":{
    "h":163.99698397757402,
    "w":41.000020286560755,
    "x":97,
    "y":1
  }
}

how can i solve this problem? I want to get array like i tried to insert

My codes:

in firebase functions: my array is part of request body

exports.createDB = functions.https.onRequest((request, response) => {
  response.header("Access-Control-Allow-Origin", "*");
  const myRequest = request.body;
  
  functions.logger.info(String(request.body));
  database.ref("diagram/"+myRequest.user.uid).set(myRequest);
  response.send(request.body);
});

I am sending the data using postman

1 Answers

SOLVED problem: When i get data using this function

database.ref("diagram/"+request.body.uid).on("value", function(snapshot) {
    //response.send(snapshot);
    response.json(snapshot);
  });

but changed it solved my problem

database.ref("diagram/"+request.body.uid).get().then(function(snapshot) {
    response.json(snapshot.val());
  });
Related