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
- rely
- Configuration
or with uri address:
- Coding
1) create an entity object
@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. - 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: - Test:
1) Insert
Results:
Here you can see the specific operating instructions:. Db.getCollection ( 'tenantNotice') Find ({})
2) Discover
Source code: https: //github.com/lovezmming/spring-development-projects/tree/master/shev-mongodb
micro-channel public number: like the wind