zoukankan      html  css  js  c++  java
  • MongoDB(二)

    传统的关系数据库一般由数据库(database)、表(table)、记录(record)三个层次概念组成,

             MongoDB是由(database)、集合(collection)、文档对象(document)三个层次组成。

             MongoDB对于关系型数据库里的表,但是集合中没有列、行和关系概念,这体现了模式自由的特点。

    Java 代码连接查询:

    try {
    MongoClientOptions.Builder build = new MongoClientOptions.Builder();
    //与数据最大连接数50
    build.connectionsPerHost(50);
    //如果当前所有的connection都在使用中,则每个connection上可以有50个线程排队等待
    build.threadsAllowedToBlockForConnectionMultiplier(50);
    build.connectTimeout(1*60*1000);
    build.maxWaitTime(2*60*1000);
    MongoClientOptions options = build.build();
    MongoClient mongoClient = new MongoClient("192.168.8.22", options);//连接地址 or localhost
    MongoDatabase mgdb = mongoClient.getDatabase("spt");
    System.out.println("Connect to database successfully!");
    System.out.println("MongoDatabase inof is : "+mgdb.getName());
    MongoCollection<Document> collection = mgdb.getCollection("spt");
    FindIterable<Document> f = collection.find(Filters.eq("id", "29e01a0f23e9461ca871e10661292895"));
    Document d = f.first();
    SugarTestCommentBean sugarComment = JsonUtils.fromJson(d.toJson(), SugarTestCommentBean.class);
    List<CommentBean> commentList = sugarComment.getComments();
    PageFinder<CommentBean> pageFinder = new PageFinder<CommentBean>();
    pageFinder.setData(commentList);
    modelMap.put("pageFinder", pageFinder);
    mongoClient.close();
    } catch (Exception e) {
    System.err.println(e.getClass().getName() + ": " + e.getMessage());
    }

  • 相关阅读:
    GoogleMaps 之创意应用——数码照片定位
    SGI面临破产
    Google地图搜索的触角伸向月球
    说“丛林法则”
    比Google Map更加清晰的网络地图——RealBird
    Office 12眩酷界面,先睹为快
    Paypal将正式登陆中国——贝宝
    地图技术的领导者RealBird与Google Maps的无缝结合
    微软欲封杀OpenGL?
    网络地图服务究竟商机何在?
  • 原文地址:https://www.cnblogs.com/shenjiangwei/p/7698409.html
Copyright © 2011-2022 走看看