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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:34:48+00:00 2026-06-08T22:34:48+00:00

I am trying to query mongodb using spring. We have a collection which holds

  • 0

I am trying to query mongodb using spring. We have a collection which holds a tree and a include a list of items as a tree path (so we can easily traverse the tree). We have a query which needs to return all child nodes of a specific node. Our query is based on selecting all nodes that have the node (parent) in the path and are one level lower than the parent (level). Our criteria is as follows:

Criteria.where("treePath").in(parentId).and("treePath").size(level)

Alas, when we call this on mongodb we get the following exception:

org.springframework.data.mongodb.InvalidMongoDbApiUsageException: Due
to limitations of the com.mongodb.BasicDBObject, you can’t add a
second ‘treePath’ expression specified as ‘treePath : { “$size” : 2}’.
Criteria already contains ‘treePath : { “$in” : [
“50137df5f49f9b4a6481d639”]}’.

Are there other suggestions on how to achieve the same? One option I was thinking of was to query mongodb directly. I tried

String command = "{findAndModify:\"Task\",query:{$and:[{treePath:\"5013a79a36600872ecf4dba8\"},{treePath:{$size:2}},{order:{$gte:0}}]},update:{$inc:{order:1}}}";
CommandResult commandResult = mongoTemplate.executeCommand(command);

But this will only update the first record and I need them all updated.

Thanks!

  • 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-08T22:34:49+00:00Added an answer on June 8, 2026 at 10:34 pm

    This will do what you want:

    int parentId = 100;
    int level = 5;
    Criteria c = new Criteria().andOperator(Criteria.where("treePath").is(parentId),  
                                            Criteria.where("treePath").size(level));
    System.out.println(c.getCriteriaObject());
    

    It prints

    { "$and" : [ { "treePath" : 100} , { "treePath" : { "$size" : 5}}]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to query a 'Favorites' model to get a list of items a user
I am trying to query the windows desktop search API using SQL. I have
Trying to do a simple mongodb query that drives me mad.... I have the
I am trying to perform a regex query using PyMongo against a MongoDB server.
Using: Spring 3.1.0.RELEASE, Spring Data MongoDB 1.0.0.RELEASE I have a document class defined like
I am using Rogue/Lift Mongo record to query MongoDb. I am trying to create
I am trying to query MongoDB and find the row which has a specific
i'm trying to do a $ne query in mongodb while using a regex, but
i'm trying, to figure out how can i make this query work in mongodb.
I'm using pymongo and currently have a single collection. The collection holds documents representing

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.