8

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?

1
  • Who -1'd this? It's a reasonably valid question. Resetting to 0 Commented Jul 22, 2011 at 9:39

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

"There is currently no way to do this." Is this answer still valid today?
This will likely always be the case. Change queries to support ranges on the key is a ton of work. Also, it cannot be indexed which is a big deal.
Rather than use terms like "no schema" or "schemaless" when explaining mongodb and similar db systems, I find it creates less confusion to say they have a variable or unrestricted schema by default.
Mongodb supports case insensitive indexing now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.