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 ??

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top