nosql database -mongodb

1 know

Library 2, the operation set

3 crud

4 pymongo

python-oriented open source database;

mysql mongdb postgreSQL REDIS are open source

 

1--Nosql

What is NoSQL?

NoSQL, refers to non-relational database. NoSQL sometimes called Not Only SQL abbreviation for collectively different from traditional relational database management system database.

NoSQL to store very large scale data. (Such as Google or Facebook every day to collect trillion bits of data for their users). These types of data storage does not require a fixed pattern, no extra operation can be extended laterally.

Why NoSQL?

Today we can through a third party platform: You can easily access and fetch data (such as Google, Facebook, etc.). User's personal information, social network, location, user generated data, and user operation log has increased exponentially. If we want to carry out these user data mining, SQL database that is not suitable for these applications, and the development of NoSQL database well able to deal with these large data.

| --1.2mongodb document type is stored

A database there are many, mongodb type is stored inside the database json, format key-value pairs

Enter the command mongo 

Exit the command exit

| --2 implicitly created, set operations library operations

2.1-mongodb Implicit creation

show dbs; display all database

mongo underlying JavaScript engine is

In mongodb inside empty database does not make sense, use test; // switch databases, (call a non-existent database mongdb will automatically create a database), but at this time because the database is empty, show dbs; invisible this database, then you must create a collection to test the database, and then shou dbs; to see the test database, which is called the implicit actions

db.createCollection('xxx')

View current database and then the inside; db;

Delete a database, switch to the database following use test; then execute the command db.dropDatabase (); you can delete the test database

collection with the collection of data on different,

use test;

show collections; Display Set

db.createCollection (col_name); create a collection

db.col_nam.drop (); Delete Collection

 

| --3; crud (create read update delete) into the document to the collection, query delete a document modify document

db.createCollection('student')

db.student.insert({"name":"LiMing","age":10,"gender":"male"});

Automatically generate an id After insertion, the id, you can specify your own

db.student.insert({"_id":"1","name":"Anny","age":20,"gender":"femal"})

No format limitations when a plurality of data inserted, the inserted field can be different, as long as the format on json

db.student.insert([ {"name":"张三","age":"20"},{"name":"李四","gender":"male"} ])

Create Operations

Creation or insert new documents are added to the collection. Have mentioned before, if there is no set of insert, the insert will create a corresponding set. MongoDB provides a method for inserting three documents:

`db.collection.insert()``db.collection.insertOne()``db.collection.insertMany()`

|| - insert a single document

Wherein, `db.collection.insertOne ()` for inserting individual documents to the collection. And `db.collection.insertMany ()` and `db.collection.insert ()` to the collection insert may be a plurality of documents. `Db.collection.insertOne ()` example is as follows:

 

 

 

 After the command is executed automatically returns a result document, the document output is as follows:

 

 

 

This documentation was inserted successfully. Wherein, `acknowledged` representative of the operating state of this operation, the state value including` true` and `false`. `InsertedId` namely the document` _id`.

Tip: The ellipses MongoShell example newline identifier. Wrap identifier for command input and execution did not affect, so this article will not focus on a unified style that example with a line break sometimes, and sometimes not with a line break.

|| - insert multiple documents

`Db.collection.insertMany ()` example is as follows:

 

 Since this insertion of the two documents, the returned results documents will show two `_id`. Return the document reads as follows:

 

 

 

Find deleted

 

db.student.find (); unconditionally find, find out everything

Find accordance with the conditions

Find the gender is male, height data 160

db.student.find({“gender”:"male","height":160})

Only show names

db.student.find({},{})

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/wsnan/p/11792644.html