成都网站建设设计

将想法与焦点和您一起共享

mongoDB中distinct的使用

需求:在MongoDB中查询一个类型(数据库中可能百万条数据)用作下拉列表查询。
在工具中用 db.getCollection('order').distinct("typeName") 即可实现。
java 代码:
MongoCollection coll = this.client.getDatabase(this.databaseName).getCollection('order');
//获得mongodb数据库连接 getCollection表名
//this.databaseName 来自配置文件直接读取动态配置,即数据库名称
Iterable iterable = coll.distinct('typeName',String);
// String 查询的值 是什么类型,由于本次查询的为汉字,所以是String
MongoCursor it = iterable.iterator();
while(it.hasNext()) {
String typeName = it.next().toString()
System.out.pringln(typeName)
}

创新互联是一家专注于网站建设、成都做网站与策划设计,牡丹江网站建设哪家好?创新互联做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:牡丹江等地区。牡丹江做网站价格咨询:028-86922220

            /*****
            MongoCollection : com.mongodb.client.MongoCollection
            Document:org.bson.Document 
            implements Map, Serializable, Bson
            **/

网页标题:mongoDB中distinct的使用
分享URL:http://chengdu.cdxwcx.cn/article/ihhieg.html