Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8356617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:14:30+00:00 2026-06-09T10:14:30+00:00

I found a StackOverflow Question that comes very close to answering my question, but

  • 0

I found a StackOverflow Question that comes very close to answering my question, but not quite there.

Take this original question (modifying a document that is in an array) but assume that you do not have a specific change you wish to make. Instead, I have a dictionary of changes that I wish to make. Here is an example:

Original Document

{
    _id: something,
    recipients: [{id:1, name:"Andrey", isread:false}, {id:2, name:"John", isread:false}]
}

Changes to be made

{
    isread: true,
    fullname: 'jonathan'
}

How can I apply this dictionary of changes to John (id:2)?
Incase it is relevant, I am using the MongoDB-Node.JS Driver
Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:14:32+00:00Added an answer on June 9, 2026 at 10:14 am

    Just like in the question you referenced, you need to use the $ positional operator, but with update in this case:

    collection.update({_id:something, 'recipients.id': 2}, {$set: {'recipients.$': {
        isread: true,
        fullname: 'jonathan'
    }}}, function (err) {...
    

    EDIT

    To not replace the whole array element object you’d have to do something like this:

    collection.update({_id:something, 'recipients.id': 2}, {$set: {
        'recipients.$.isread': true,
        'recipients.$.fullname': 'jonathan'
    }}, function (err) {...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm very aware that this is probably not a stackoverflow question, but i figure
I found this answer to this question https://stackoverflow.com/a/7244888/1473523 , but in my situation am
I've found this question on StackOverflow Adding div below images in colorbox But it
This question might appear very simple, but i haven't found an answer yet, so
this is my first question on StackOverflow, but I think that we'll both come
I've found some similar questions on StackOverflow, but nothing that addresses what I'm looking
I've looked around on stackoverflow for a similar question, but haven't found exactly what
I've found a similar question, but the accepted answer is not what I want:
There's a risk that this either comes across as a language-troll or a failure
I have searched Google and Stackoverflow for this question, but I still don't understand

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.