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

289
Views
Using mongodb, how would someone update a certain string inside an array?

So, while building a webpage, I'd like to add a feature where you can change your password, email etc.. And I have all that info stored inside my database kinda like this:

// This is what it looks like in mongodb compass
Credentials: Array
0:
"email"
1:
"password"

how could I update 0 or 1?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use dot notation to set the postion you want in this way (assuming position 0 is always email and position 1 is always password):

db.collection.update({
  "user": "your_user_or_whatever_way_to_identify"
},
{
  "$set": {
    "credentials.0": "new email",
    "credentials.1": "new pass"
  }
})

Example here

over 4 years ago · Santiago Trujillo 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!