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());
    }

  • 相关阅读:
    insert client ip for TCP::option
    域名注册管理相关的三个机构:ICAAN、interNIC、CNNIC
    如何配置让80端口转到8080端口上
    程序员应该怎样应对“扯皮”
    Spring Bean的常用注解与配置【转载】
    Auth2.0 例子【转载】
    单点登录原理与简单实现【转载】
    RBAC用户权限管理数据库设计【转载】
    产品经理的工作职责(笔记)
    算法竞赛中阶乘之和的优化
  • 原文地址:https://www.cnblogs.com/shenjiangwei/p/7698409.html
Copyright © 2011-2022 走看看