How do I search by a query expression in MongoDB? Something like Lastname+Firstname, where Lastname and Firstname are two separate fields? The search string would then be SmithJohn. Is this possible? Can I still take advantage of indexing?
The indexes are defined like ensureIndex({LastName:1, FirstName:1},{unique:true})
I should mention that this will be the index of the collection. I actually, more importantly, will need to be able to find the data (which is the full match of the index) without knowing which collection or index I'm dealing with and get it all using the collection name (which is supplied). It might be a simple or compound index, but doesn't need to be anything else. One collection has the Date_1, another has Lastname_1_Firstname_1 for the index.
A typical request looks like /col/people/key/SmithJohn
. I have a few simple indexes as well, like /col/events/key/2014-05-05
.
Just a side note. With ensureIndex({LastName:1, FirstName:1},{unique:true})
, will a name like Matt Hat conflict with Mat That (notice the T).