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

38 views
Skip to first unread message

Manoj Prasanna Handapangoda

unread,
Oct 11, 2013, 8:26:21 PM10/11/13
to play-fr...@googlegroups.com
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<Person> pList =  ds.createQuery(Person.class).field("id").startsWith("95").asList();  // this is not working 
Any ideas how get this done ??

green

unread,
Oct 13, 2013, 6:01:26 AM10/13/13
to play-framework
what about ds.createQuery(Person.class).filter("id >", 950).filter("id <", 960).asList() ?

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Justin Lee

unread,
Oct 13, 2013, 10:14:49 AM10/13/13
to play-framework

startsWith() is a text operation.  It can't be used on numeric values.  You'll have to use greaterThan/lessThan comparisons.

Manoj Prasanna Handapangoda

unread,
Oct 13, 2013, 10:46:08 PM10/13/13
to play-fr...@googlegroups.com
Great, the used with <,> worked for me.
Thanks.
Reply all
Reply to author
Forward
0 new messages