Search code examples
mongodbmorphia

search in a map field


I'm using morphia. As u know for a simple search I can use this:

q.field("fieldname").containsIgnoreCase(texttosearch); 

But my field type is map. So I must change it like this(use dot):

q.field("mapname.fieldname").containsIgnoreCase(texttosearch);

But again I want to search in all fields. I can simply do this by repeating for all fields. The problem is my field count is not static. How can I solve this?


Solution

  • You should store it not as a map, but as an array/list of key/value pairs. Then you can search the key field, and index it. This is not something morphia does for you at the moment but something which could be an alternate storage format for Map. It would be a very different format.

    Take a look at this discussion for more background