Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB case insensitive key search

I am able to query values without regard to case, but I would like to to query keys insensitively, so users can type them in all lower case.

This doesn't work, because it is not valid JSON:

{
   /^lastName$/i: "Jones"
}

Is there a strategy I could use for this, besides just making a new collection of keys as values?

like image 498
axiomx11 Avatar asked Jul 21 '11 17:07

axiomx11


1 Answers

There is currently no way to do this.

MongoDB is "schema-free" but that should not be confused with "doesn't have a schema". There's an implicit assumption that your code has some control over the names of the keys that actually appear in the system.

Let's flip the question around.

  • Is there a good reason that users are inserting case-sensitive keys?
  • Can you just cast all keys to lower-case when they're inserted?

Again, MongoDB assumes that you have some knowledge of the available keys. Your question implies that you have no knowledge of the available keys. You'll need to close this gap.

like image 121
Gates VP Avatar answered Sep 22 '22 07:09

Gates VP