mongodb under docker

Mongodb developed under Docker

mogodb Introduction

MongoDB 是一个基于分布式文件存储的数据库。

A lot of people will mongodb and mysql contrast, mongodb non-relational database (nosql), belonging to the document database, simply read the job situation for a number of high-volume, it does not support complex sql, initially the most widely used is the logging system.
mysql: data storage, the relational database.
mongodb: nosql, non-relational database.
Redis: NoSQL
Redis suitable for frequent users, you need to pressure the project, the final data will be put in storage.

mongodb Case

springboot Case

  1. rely
    org.springframework.bootspring-boot-starter-data-mongodb
  2. Configuration
    Here Insert Picture Description
    or with uri address:
    Here Insert Picture Description
  3. Coding
    1) create an entity object
    Here Insert Picture Description
    @Data is lombok notes, contains getter and setter methods
    @Document declared mongodb data entities
    2) implementation
    Notes:
    @Autowired
    Private MongoTemplate mongoTemplate;
    Interface:
    @PostMapping ( "/ the Save")
    public String Save (String @RequestBody JSON)
    {
    a Date = new new DATE a Date ();
    tenantNotice tenantNotice new new tenantNotice = ();
    String ID = "XXXX";
    tenantNotice.setId (ID);
    tenantNotice.setContent (JSON);
    tenantNotice.setTenantId ( " 000001 ");
    tenantNotice.setTitle (JSON);
    tenantNotice.setCreateTime (DATE);
    tenantNotice.setUpdateTime (DATE);
    mongoTemplate.insert (tenantNotice);
    return tenantNotice.getId ();
    }
    @GetMapping ( "/ GET")
    public TenantNotice GET (String ID)
    {
    Query Query = Query.query (Criteria.where ( "_ ID") IS (ID).);
    List tenantNotice mongoTemplate.find = (Query, TenantNotice. class);
    return tenantNotice.get (0);
    }
    @PostMapping ( "/ del")
    public void del (String ID)
    {
    Query Query = Query.query (Criteria.where ( "_ ID") IS (ID)).;
    mongoTemplate.findAndRemove (Query, TenantNotice.class);
    }
    the interface template has many features, features may require its own package.
  4. docker installation and deployment
    download the image:
    docker pull Mongo
    start:
    docker RUN -p 27017: 27017 -v $ the PWD / DB: / Data / DB --name Mongo MongoDB -d: Latest
    follows:Here Insert Picture Description
  5. Test:
    1) Insert Here Insert Picture Description
    Results:
    Here you can see the specific operating instructions:. Db.getCollection ( 'tenantNotice') Find ({}) Here Insert Picture Description
    2) Discover
    Here Insert Picture Description

Source code: https: //github.com/lovezmming/spring-development-projects/tree/master/shev-mongodb
micro-channel public number: like the wind
Here Insert Picture Description

Published 10 original articles · won praise 8 · views 866

Guess you like

Origin blog.csdn.net/zmzmlla/article/details/103121504