简体   繁体   English

如何使用morphia,mongodb,play框架按整数类型列进行搜索

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

HI I have following data items in mongo db 您好,我在mongo db中有以下数据项

{ "id" : 950, "name" : "Name 1" }, { "id" : 951, "name" : "name 2" } {“ id”:950,“ name”:“名称1”},{“ id”:951,“ name”:“名称2”}

I have tried mapping id as both Integer and String. 我尝试将ID映射为Integer和String。

and I used morphia + play to connect mongodb and used DAO of morphia. 我使用了morphia + play连接mongodb,并使用了morphia的DAO。 I need to do a search by id like (in sql where id like '95%' ) and get the result as list. 我需要按ID进行搜索(在sql中,id类似于“ 95%” ),并将结果作为列表获取。

List pList = ds.createQuery(Person.class).field( "id" ).startsWith( "95" ).asList(); 列表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. startsWith()是基于文本的操作。 It doesn't work against numbers. 对数字不起作用。 you'll have to use a greaterThan/lessThan query for range checking. 您必须使用GreaterThan / lessThan查询进行范围检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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