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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:32:00+00:00 2026-05-28T03:32:00+00:00

i try to query MongoDB via Casbah for a field that is a array

  • 0

i try to query MongoDB via Casbah for a field that is a array of strings with a regexp.

For example:

I have a Maschine with a list of ips, that are stored as string in the fields ips.
Now i want to search for all machines that have the subnet 192.168.

For me i looks like that the i cannot query an array with a regexp applied to every entry and if one of the entries matches the machine is returned.

Any way to make such a query ?

— Fixed

Thanks for your help.

Everything works now. At the end i need to work around one limitation of Casbah, because i needed to join to queries with $or and Casbah complains about missing implicits with the regexp.

My final code for a RegExp Array query with an additional other field is:

val regexp = ".*" + parameter + ".*"
val nameQ = MongoDBObject("serverName" -> regexp.r)
val ipsQ = MongoDBObject("ips" -> regexp.r)
val bldr = MongoDBList.newBuilder
bldr += ipsQ
bldr += nameQ
val query = MongoDBObject("$or" -> bldr.result.asDBObject)
val result = find(query)

It is not the nicest code and the string concatenation of the parameter needs to be fixed. But it works 🙂

  • 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-28T03:32:01+00:00Added an answer on May 28, 2026 at 3:32 am

    You can ignore the fact that this is an array:

    > db.rx.insert( { "ips" : ["192.168.1.231", "192.168.2.231", "120.32.42.51"] });
    > db.rx.find( { ips : /192./ } )
    { "_id" : ObjectId("4f104f0183bfca7a48b60da1"), 
      "ips" : [ "192.168.1.231", "192.168.2.231", "120.32.42.51" ] }
    

    MongoDB always behaves like this: if you treat an array just like a normal field, it will apply the operation to each member and, if one matches, consider the parent document a match.

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

Sidebar

Related Questions

i try to write a query with Casbah and Salat to query a field
I have an object that has an instance of Doctrine\ODM\MongoDB\Query\Builder . When I serialize
I have MongoDB.BsonDocument, i want to convert that BsonDocument to List of collection, how
I'll try to explain this better on another question. This is the query that
I have been having a problem where after my mongodb connection to mongohq via
I'm trying to use mongodb with PHP. For that, I have created a MongoHQ
i've got this stored procudure that won't work. If I try this query in
I have a query in my android app that pulls all image paths from
I'm using the following HQL query to try and load a set of objects
I'm trying to use Subsonic 3.0 but with every query I try it gives

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.