Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
How to put a variable inside firestore property names in javascript?

I'am trying to do put a variable inside a firestore property, Here is my example:

exports.handler = function(admin, data) {
    const userId = data.userId;

    return admin.firestore().collection('users')
    .doc(userId)
    .update(
    {
        `userInfos.${userId}`: admin.firestore.FieldValue.delete()
    })
}

Also I try to declare a string before the query and use this string as a property name yet that cause another failure.

    const newField = `userInfos.${userId}`;

    return admin.firestore().collection('users')
        .doc(userId)
        .update(
        {
            newField: admin.firestore.FieldValue.delete()
        })

Is there any way to do that, or I have to change my data structure?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The quickest way to make that second snippet work is to put the field name in square brackets:

const newField = `userInfos.${userId}`;

return admin.firestore().collection('users')
    .doc(userId)
    .update({
        [newField]: admin.firestore.FieldValue.delete()
    })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!