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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:53:05+00:00 2026-06-10T01:53:05+00:00

I recently spent some time trying to use the $pull operator through Spring’s Data

  • 0

I recently spent some time trying to use the $pull operator through Spring’s Data MongoOperations interface, so I thought it would be nice to share my findings in case anyone bumps into a similar problem.

So here it goes…

I have 2 java POJOs like so :

@Document
public class OutterObject{

    private String id;
    private String name;
    private List<InnerDocument> innerDocs;


    //SETTERS - GETTERS Ommited


public class InnerDocument{


    private String id;
    private String name;

         //SETTERS - GETTERS Ommited

This is stored in a Mongo collection like so :

 "_id" : "doc2",
 "_class" : "OutterObject",
 "name" : "doc2",
 "innerDocs" : [{
      "_id" : "innerDoc21",
      "name" : "innerDoc21"
  }, {
      "_id" : "innerDoc22",
      "name" : "innerDoc22"
  }]

I’m trying to use the $pull operator in order to remove all objects inside the innerDoc collection having a name value = “innerDoc22”.

I know how to accomplish this using the mongo driver like so :

 List<String> ids = 
         Arrays.asList("innerDoc22");

 BasicDBObject find = new BasicDBObject();

 match.put("innerDocs.name", 
           BasicDBObjectBuilder.start("$in", ids).get());

    BasicDBObject update = new BasicDBObject();
        update.put(
                "$pull",
                BasicDBObjectBuilder.start("innerDocs",
                        BasicDBObjectBuilder.start("name", "innerDoc22").get()).get());

  DBCollection col= mongoOperations.getDb().getCollection("outterObject");

  col.update(find , update);

I’m trying to accomplish the same thing using Spring’s MongoOperations Interface.
Here is my code using the MongoOperations interface :

List<String> ids = Arrays.asList("innerDoc22");

Query removeQuery = Query.query(Criteria.where("innerDocs.name").in(ids));

WriteResult wc = mongoOperations.upsert(
                    removeQuery, 
                    new Update().pull("innerDocs.name", "innerDoc22"), 
                    OutterObject.class);
System.out.println(wc.getLastError());

I’m not getting any errors when calling getLastError() the update is simply not done in the database.

I know a similar question has already been asked here but the answer that was given does not use the MongoOperations interface.

  • 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-10T01:53:07+00:00Added an answer on June 10, 2026 at 1:53 am

    After searching a bit and looking at the source code I realized that I needed to pass an InnerDocument object as a second parameter to the pull method so that the spring classes would be able to do the mapping correctly.

    As it turns out I can navigate objects while selecting objects (I’m using “innerDocs.name” in the removeQuery) but I cannot (or havent found a way) do the same when updating a document.

    Below is how I implemented the query using MongoOperations :

    List<String> ids = Arrays.asList("innerDoc22", "innerDoc21");
    
    Query removeQuery = Query.query(Criteria.where("innerDocs.name").in(ids));
    
    WriteResult wc = 
           mongoOperations.upsert(removeQuery, 
               new Update().pull("innerDocs", 
               new InnerDocument("innerDoc22", null)), 
               OutterObject.class);
    
    System.out.println(wc.getLastError());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently spent some time trying to write some numbers as bytes to pipe
Recently I spent quite some time writing various Visual Studio Extensions projects. Even though
I recently spent some time chasing an annoying little bug and I'm looking for
I recently spent some time hunting down a typo in my C++ templates. g++
I recently spent some time looking for best practices on preventing browsers from caching
I already spent some time developing small projects with the GWT and I recently
I've recently spent a good deal of time performing detailed UML designs of various
I spent a lot of time programming in Java recently, and one thing I
I have spent a lot of time recently reading the HTTP 1.1 specification and
Was recently using some code along the lines of $(#divMenuContainer:visible).hide(explode); However after some time

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.