Question

HI I have following data items in mongo db

{ "id" : 950, "name" : "Name 1" }, { "id" : 951, "name" : "name 2" }

I have tried mapping id as both Integer and String.

and I used morphia + play to connect mongodb and used DAO of morphia. I need to do a search by id like (in sql where id like '95%' ) and get the result as list.

List pList = ds.createQuery(Person.class).field("id").startsWith("95").asList(); // this is not working Any ideas how get this done ??

Was it helpful?

Solution

Having already answered on the play mailing list and the morphia list, i'll answer here so others will see it, too. startsWith() is a text based operation. It doesn't work against numbers. you'll have to use a greaterThan/lessThan query for range checking.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top