質問

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