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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:48:54+00:00 2026-05-25T15:48:54+00:00

I have the following structure in my document: { _id : ObjectId(43jh4j343j4j), array :

  • 0

I have the following structure in my document:

{
  _id : ObjectId("43jh4j343j4j"), 
  array : [
            { 
              _arrayId : ObjectId("dsd87dsa9d87s9d7"),
              someField : "something",
              someField2 : "something2"
            },
            { 
              _arrayId : ObjectId("sds9a0d9da0d9sa0"),
              someField : "somethingElse",
              someField2 : "somethingElse2"
            }
   ]
 }

I want to update someField and someField2 but only for one of the items in the array, the one that matches _arrayId (e.g. _arrayId : ObjectId("dsd87dsa9d87s9d7"); and only for this document (e.g. _id : ObjectId("43jh4j343j4j") ) and no other.

The arrayIds are not unique to the document that’s why I need it to be for a specific document. I could use the $ positional operator if I wanted to update that value within the array for every document it exists in, but that’s not what I want.

I am trying to accomplish this in java but a command line solution would work as well.

  • 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-05-25T15:48:55+00:00Added an answer on May 25, 2026 at 3:48 pm

    You could still use $ positional operator to accomplish this. But you need to specify the objectid of the parent doc along with the _arrayid filter. The below command line query works fine

    db.so.update({_id:ObjectId("4e719eb07f1d878c5cf7333c"),
                  "array._arrayId":ObjectId("dsd87dsa9d87s9d7")},
                  {$set:{"array.$.someField":"updated"}})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document structure something along the lines of the following: { "_id"
I have something that looks like the following document structure: public class Document {
I have a set of records with the following structure: {u'_id': ObjectId('4e60fc677fdfb50fc3000000'), u'columns': [
I have the following structure of my HTML document: <div id=slideshow></div> <div id=content></div> $('#slideshow').css({
I have a document with the following structure: { tags: ['bbb', 'aaa', 'ddd', 'ccc']
Lets say we have the following document structure: class BlogPost { [MongoIdentifier] public Guid
I have following structure of an HTML document: <body> <div class=main> <div class=left></div> <div
I have an xml document with the following structure: <?xml version=1.0 encoding=UTF-8?> <items> <item>
I have an XML document with following structure: root element DataModel can have children
I have following structure with example data: id season_id title 1 1 Intro 2

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.