简体   繁体   中英

How to search by integer type column using morphia, mongodb, play framework

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM