MongoDB study notes (a, MongoDB entry)

table of Contents:

  • Why use nosql
  • Introduction of mongo
  • Scenarios
  • Getting demo

Why use nosql:

With the development of the Internet, the surge in the number of users, up visits, the traditional performance relational database also tends to bottleneck .

Relational database insurmountable problems:

1, high concurrent read and write: Why relational database difficult to support high concurrent read and write it, because it is based on disk IO operations, and nosql general direct operating memory.

2, efficient mass data storage and access

3, high scalability, high availability

。。。。。。

Relational database binding:

1, constrained transactional consistency; support high concurrency has been very difficult, but also need to meet the data consistency.

2, read and write real-time requirement

。。。。。。

What nosql, it features:

nosql (Not Only SQL), is a data storage technology, as opposed to traditional sql but it is not bound to follow some nature.

1, features:

  • Support for mass data storage
  • Break the performance bottleneck
  • easy to use
  • Open source support
  • Server performance requires low

2. Disadvantages:

  • It does not support transactions
  • Complex sql difficult to achieve (similar to multi-table association)
  • and many more

mongo's profile:

mongo features:

1, a collection of documents for storage: storage bson form (extended JSON) data

2, free storage format: data format is not fixed, modify the data structure does not affect the operation of the service

3, powerful query, comparable to sql

4, complete index, query plan support

5, support for data replication and failover

6, support for efficient storage of binary large object data and documents

7, using slice groups to enhance the system performance

8, using memory-mapped storage engine, the disk IO operations into memory operations

。。。。。。

mongo concept and rdms comparison:

If there is a relationship between the user and mailbox storage needs:

1, in the sql generally requires two tables to implement and requires a mailbox table field associated user; User (user table), In Email (mailbox table, many)

2, but you only need to email mongo in that field designed array type on it

{
    _id: 0001
    username: 'zd'
    email: [
        '[email protected]',
        '[email protected]'
    ]
}

Scenario:

As long as the project contains two or more features, choose mongo absolutely wrong! ! !

Getting Started demo:

1, mongodb-drive-dependent increase in

1 <dependency>
2     <groupId>org.mongodb</groupId>
3     <artifactId>mongodb-driver</artifactId>
4     <version>3.4.3</version>
5 </dependency>

2, obtaining a document data

 1 public class Test {
 2 
 3     public static void main(String[] args) {
 4         MongoClient client = new MongoClient("192.168.233.128", 27017);
 5         MongoDatabase db = client.getDatabase("local");
 6         MongoCollection<Document> user = db.getCollection("user");
 7         for (Document next : user.find()) {
 8             Object name = next.get("name");
 9             Object age = next.get("age");
10             System.out.println(MessageFormat.format("name={0}, age={1}", name.toString(), age.toString()));
11         }
12     }
13 }

Guess you like

Origin www.cnblogs.com/bzfsdr/p/11924464.html