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

  • Home
  • SEARCH
  • 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 7795953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:13:18+00:00 2026-06-01T23:13:18+00:00

I have JSON object : { _id : 1, _class : com.model.Test, projectList :

  • 0

I have JSON object :

{ “_id” : “1”, “_class” : “com.model.Test”, “projectList” : [ {
“projectID” : “Spring”, “resourceIDList” : [ “Mark”,”David” ] },
{ “projectID” : “MongoDB”, “resourceIDList” : [ “Nosa ] }

I need to be able to remove the resourceIDList for Project “Spring” and assign a new ResourceIDList.

The ResourceIDList is just List

Whenever I try to use the following,nothing is updated at DB:

 Query query = new Query(where("_id").is("1").and("projectID").is("Spring"));    

 mongoOperations.updateMulti( query,new Update().set("ressourceIDList",  populateResources()), Test.class);
  • 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-01T23:13:19+00:00Added an answer on June 1, 2026 at 11:13 pm

    Replacing the resourceIDList in the embedded document matching {“projectList.projectID”:”Spring”} may be accomplished in the JavaScript shell like so:
    (I like to start with the JS shell, because it is less verbose than Java and the syntax is relatively straightforward. Examples with JS can then be applied to any of the language drivers.)

    > db.collection.update({_id:"1", "projectList.projectID":"Spring"}, {$set:{"projectList.$.resourceIDList":["Something", "new"]}})
    

    The documentation on using the “$” operator to modify embedded documents may be found in the “The $ positional operator” section of the “Updating” documentation:
    http://www.mongodb.org/display/DOCS/Updating#Updating-The%24positionaloperator
    There is more information on embedded documents in the “Dot Notation (Reaching into Objects)” Documentation:
    http://www.mongodb.org/display/DOCS/Dot+Notation+%28Reaching+into+Objects%29

    The above may be done in the Java Driver like so:

    Mongo m = new Mongo("localhost", 27017);
    DB db = m.getDB("test");
    DBCollection myColl = db.getCollection("collection");
    ArrayList<String> newResourceIDList = new ArrayList<String>();
    newResourceIDList.add("Something");
    newResourceIDList.add("new");
    BasicDBObject myQuery = new BasicDBObject("_id", "1");
    myQuery.put("projectList.projectID", "Spring");
    BasicDBObject myUpdate = new BasicDBObject("$set", new BasicDBObject("projectList.$.resourceIDList", newResourceIDList));
    myColl.update(myQuery, myUpdate);
    System.out.println(myColl.findOne().toString());
    

    If you have multiple documents that match {“projectList.projectID” : “Spring”} you can update them at once using the multi = true option. With the Java driver it would look like this:

    myColl.update(myQuery, myUpdate, false, true);
    

    In the above, “false” represents “upsert = false”, and “true” represents “multi = true”. This is explained in the documentation on the “Update” command:
    http://www.mongodb.org/display/DOCS/Updating#Updating-update%28%29

    Unfortunately, I am not familiar with the Spring framework, so I am unable to tell you how to do this with the “mongoOperations” class. Hopefully, the above will improve your understanding on how embedded documents may be updated in Mongo, and you will be able to accomplish what you need to do with Spring.

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

Sidebar

Related Questions

I have this json object : { msg_id:134, message:Dick, comment:[ { com_id:9, comment:test, msg_id:134,
I have a json object coming in as { c_id: 261, customer_id: 178729, name:
I have a json object collection of geo locations that I build in the
I have a JSON object which is generated by PHP. It's an object with
I have a JSON object containing a number of strings. I also have a
I have a JSON Object that is returned from a web service call that
hello all i have one json object like {event1:{title:My birthday,start:12\/27\/2011 10:20 ,end:12\/27\/2011 00:00 },event2:{title:My
So I have a json object which has a structure like so: { John
Hi I have a JSON object that is a 2-dimentional array and I need
Lets say that I have a JSON object called fruits and this is the

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.