• JAVA-查看MongoDB中的数据(包含List集合)


    package com.xinsight.server;
    
    import java.net.UnknownHostException;
    import java.util.ArrayList;
    import java.util.List;
    
    import com.mongodb.BasicDBObject;
    import com.mongodb.DB;
    import com.mongodb.DBCollection;
    import com.mongodb.DBCursor;
    import com.mongodb.DBObject;
    import com.mongodb.Mongo;
    import com.xinsight.Util.BeanUtil;
    import com.xinsight.Util.InitMongodb;
    import com.xinsight.Util.Manager;
    import com.xinsight.server.model.PhoneEntity;
    /**
     *查找Mongodb中列中的List集合 
     */
    public class FindMongodbServer {
        public static void main(String args[]){
            try {
                Mongo mg = new Mongo("localhost",27017);
                DB db = mg.getDB("admin");
                if(db.authenticate("aa", "aa".toCharArray())){
                    db = mg.getDB("dxtext");
                    DBCollection dbc = db.getCollection("zq1");
                    DBCursor u = dbc.find();
                    while(u.hasNext()){
                        String n = "";
                        BasicDBObject obj = (BasicDBObject)u.next();
                        ArrayList<BasicDBObject> list = (ArrayList<BasicDBObject>)obj.get("l");
                        for(BasicDBObject basi : list){
                            n += basi.getString("n") + "_" + basi.getString("t") + "#";  //将list中的数据拼接
                        }
                        n = n.substring(0, n.length() - 1);
                        System.out.println(n);
                        int sum = 0;  //总共接听电话次数
                        String strs[] = n.split("#");
                        for(int i = 0;i < strs.length;i++){
                            int a = Integer.parseInt(strs[i].split("_")[1]);
                            sum +=a;
                        }
                        System.out.println(obj.get("n") + "  " + sum);  //主叫号码     总共接听次数
                        System.out.println("----------------------");
                        Thread.sleep(1000);
                    }
                }
            } catch (UnknownHostException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
  • 相关阅读:
    十六进制计算器
    USB 3.0规范中译本 第7章 链路层
    from表单POST提交nodejs
    07_通过谷歌封装的api操作数据库delete&insert
    06_直接执行sql操作数据库delete&update
    05_直接执行sql操作数据库
    04_数据库升级onUpgrade&ondowngrade
    03_通过OpenHelper获取SqliteDatabase对象
    02_SQliteOpenHelper介绍&oncreate方法介绍
    00_前情回顾&今日展望
  • 原文地址:https://www.cnblogs.com/zqzdong/p/4839015.html
Copyright © 2020-2023  润新知