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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:28:53+00:00 2026-05-29T09:28:53+00:00

Ok, the idea is this: Given a model such as: Release { Work[] works

  • 0

Ok, the idea is this:

Given a model such as:

Release {

   Work[] works = ....

}

and

Work {

   String title;

}

I get how to search for Releases using as criteria “has a Work with title=whatever”:

DBObject crit = new BasicDBObject();
crit.put("works", new BasicDBObject("$elemMatch",new BasicDBObject("title", "whatever")));

I also get how to use regex for basic stuff, such as “get all Works which have a tile containing whatever”:

crit.put("title", "/.*whatever.*/");

But how do I go about doing something like “get all Releases which have a Work with title that CONTAINS whatever” ?

If I try this, I get nothing:

crit.put("works", new BasicDBObject("$elemMatch",new BasicDBObject("title", "/.*whatever.*/")));

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-05-29T09:28:54+00:00Added an answer on May 29, 2026 at 9:28 am

    Well, ok, I had pretty much the same issue as the one presented in this question:

    MongoDB Regex Query : Why doesn't this work?

    Basically if, using the Java driver, you put your regular expression such as

    new BasicDBObject("title", "/.*whatever.*/")
    

    it will not work (though their documentation and the mongo console test sais it should)

    however, if you use the more verbose way of declaring your regex criteria, it will work:

    crit.put("works", new BasicDBObject("$elemMatch",new BasicDBObject("title",new BasicDBObject("$regex",".*whatever.*"))));
    

    It get’s even messier. If you want your regex pattern to be applied case-insensitively, adding the $options:'i' name value pair to the regex criteria object such as:

    new BasicDBObject("$regex",".*whAteVer.*").put("$options","i")
    

    will not work either.

    Instead you have to put the insensitivity regex flag INSIDE your regex string like this:

    new BasicDBObject("$regex",".*((?i)whAteVer).*")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have no idea why this doesn't work, but doing some validation functions and
I'm using Microsoft's idea for storing resource and booking information. In short, resources, such
When I have a given django model class like this: class BaseClass(models.Model): some_field =
I'm using Python/Django, but this is more about the data model and how I
This is a weird one, but hopefully someone can give me an idea here.
I have this idea for a free backup application. The largest problem I need
I got this idea a long time ago when i saw an app do
I had this idea of creating a count down timer, like 01:02, on the
Any idea why this code: extern C __declspec(dllexport) void Transform(double x[], double y[], int
Any idea why this wont print the errors? // Validate the email if (preg_match($regex,

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.