0
const signupTime =admin.database.ServerValue.TIMESTAMP
    
    database.ref(`/admin/vendorOrder/${vendor}/${userID}`).set(signupTime);
    console.log(signupTime);

i want the time value while in database it returns correctly enter image description here

in consol log it returns enter image description here

how do i make it return value in string

also

database.ref(`/admin/vendorOrder/${vendor}/${userID}/${signupTime}/order`).set(order);

returns error enter image description here kindly help

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
Roy Sougat
  • 83
  • 7

1 Answers1

2

As explained in the doc, with ServerValue.TIMESTAMP you get "a placeholder value for auto-populating the current timestamp as determined by the Firebase servers".

In other words signupTime does not contain the value of the timestamp, since this one is set on the server (the back-end) when you write to the database.

If you want to get this value in your Cloud Function (or in a front-end), you need to query the newly set database node, as follows, for example:

  const signupTime = admin.database.ServerValue.TIMESTAMP

  const database = admin.database();
  const ref = database.ref(`/admin/vendorOrder/${vendor}/${userID}`);

  ref
    .set(signupTime)
    .then(() => {
      return ref.get();
    })
    .then((snap) => {
      console.log(snap.val());
    })
    .catch((error) => {
      console.log(error);
    });
Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121