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 7923249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:15:04+00:00 2026-06-03T17:15:04+00:00

We have some embedded documents that look like this: { _id : ObjectId(4e402353bc9f6ec5a6000001), first_name

  • 0

We have some embedded documents that look like this:

 {
"_id" : ObjectId("4e402353bc9f6ec5a6000001"),
"first_name" : "Chris",
"last_name" : "Jones",

    "alerts" : [
    {
        "_id" : ObjectId("4f7cd6ffc067db00070022d4"),
        "name" : "Default",
        "email_frequency" : "weekly",
        "interested_industries" : [
            "Computer Software",
            "Internet"
        ],
        "interested_employers" : [
            "Facebook",
            "AOL"
        ],
        "interested_skills" : [ ],
        "matches" : [
            ObjectId("4ee46a2a0dd0c70017000365"),
            ObjectId("4efa1707bacfa40001012b65"),
            ObjectId("4e402376bc9f6ec5a6000a7a"),
            ObjectId("4e4e0eb8d052fc4028021f66"),
            ObjectId("4ee55d8500ca410014000003"),
            ObjectId("4ee63d06d96b850001008688"),
            ObjectId("4e57be7ed052fc606a002335"),
            ObjectId("4f05d47d9ce340001702ba42"),
            ObjectId("4f200ffcaf5f34000e0021a4"),
            ObjectId("4e4de701d052fc33da00052f")
        ],
        "updated_at" : ISODate("2012-05-03T18:26:14.774Z")
    }
]
 }

Since the document above is contained in an array, I’m having trouble picking it out form the selector with something like this:

User.collection.update({"_id" => user.id}, {:$set => {"alert.matches" => matches}})

But this will update all #alerts matches. I just want to update the one alert with the ID “4fa7fd60e5be08bcc9000644”.

  • 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-03T17:15:05+00:00Added an answer on June 3, 2026 at 5:15 pm

    You can probably use the positional operator to identify the array element:

    The $ positional operator

    The $ operator (by itself) means “position of the matched array item in the query”. Use this to find an array member and then manipulate it.

    So perhaps something like:

    User.collection.update(
        { :_id => user.id, :matches => BSON::ObjectId('4e40238dbc9f6ec5a6000eed') },
        { :$set => { 'alert.matches.$' => matches } }
    )
    

    But as Sergio notes, it is difficult to tease out the structure of your documents based on the limited information in your question.


    Looks like more information came in after I answered and it looks like:

    { :$set => { 'alerts.$.matches' => ... } }
    

    is what you need. And you will need to include :matches in the query so that $ has something to refer to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some Flash swfs that are embedded using swfobject and I pass them
I have an application on the Compact Framework that has some large embedded resources
So, I am having some issues with user authentication in embedded documents. I have
I have some javascript that ends up programatically clicking on a button: document.getElementById(myButton).click(); This
I have a small set of structured data items that I would like embedded
assume that i have a BlogPost model with zero-to-many embedded Comment documents. can i
Recently I've been working on some embedded devices, where we have some structs and
I have seen some mails which has HTML content embedded in them. The content
I have the following code snippet embedded into some of my divs so when
I have some files that are uuencoded, and I need to decode them, using

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.