1

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.