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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:05:52+00:00 2026-06-05T03:05:52+00:00

I have set up MongoDB following this tutorial http://www.littlelostmanuals.com/2011/09/spring-mongodb-type-safe-queries.html Everything works as expected but

  • 0

I have set up MongoDB following this tutorial

http://www.littlelostmanuals.com/2011/09/spring-mongodb-type-safe-queries.html

Everything works as expected but now I’m stuck at a point where I want to be able to query on multiple fields.

Currently I have repository interfaces for each type I’m saving and can search on a single field fine.

public interface StartedEventRepository extends 
    MongoRepository<DatablockStartedEvent, String>,
    QueryDslPredicateExecutor<DatablockStartedEvent> { 

}

Below is the query for a single parameter.

        return startedEventRepo
            .findOne(QDatablockStartedEvent.datablockStartedEvent.searchId
                    .eq(searchId));

Is it possible to create a Query object where I can say something similar to the following.

if(someName != null){
    query.where(QMyClass.name.eq(someName));
}
if(someTime != null){
    query.where(QMyClass.time.eq(someTime));
}

List result = query.list();

I’ve tried looking at the MongodbQuery but I couldn’t get it to work. Any ideas?

I saw an example http://www.mkyong.com/mongodb/spring-data-mongodb-update-document/ but this uses the mongoTemplate. Is there no way to achieve this through the repositories and if not, are they useless?

  • 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-05T03:05:54+00:00Added an answer on June 5, 2026 at 3:05 am

    It should be possible. Something like this maybe

    BooleanBuilder builder = new BooleanBuilder();
    
    if(someName != null){
        builder.and(QMyClass.name.eq(someName));
    }
    if(someTime != null){
        builder.and(QMyClass.time.eq(someTime));
    }
    
    repository.findAll(builder.getValue())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails 3.2.1 app name: demo database: mongoDB with mongoid I have this scaffolding set
I have this following SQL and I would like to know the MongoDB equivalent.
Is MongoDB _id unique by default, or do I have to set it to
I have set up a datepicker in a form using the following js: $(#Expiry).datepicker({
I have a data set in MongoDB that involves a large set of emails
We are just giving MongoDB a test run and have set up a Rails
I have a set of objects in Mongodb that each have a set of
I have a mongodb replicaset on ubuntu.. In replica set, hosts are defined as
MongoDB for C#, I started following their tutorial but the compile error I get
I have the following mongodb object: { _id: ObjectId(4d0b9c7a8b012fe287547157), messages: { 0: { toUname:

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.