1. Introduction
mongodb is an open source nosql database system based on distributed file storage written in C++ language. It supports document and key-value storage models, has a flexible data model, reliable performance, and automatic throughput capacity expansion.
MongoDB stores data as a document, and the data structure consists of key-value (key=>value) pairs. MongoDB documents are similar to JSON objects. Field values can contain other documents, arrays, and arrays of documents.
2. Main Features
High performance, easy to deploy, easy to use, easy to store data
MongoDB is a database for document storage, which is relatively simple and easy to operate
Data mirroring can be created locally or over the network, which makes MongoDB more scalable
Mongo supports rich query expressions. The query command uses JSON format markup, which can easily query the objects and arrays embedded in the document
MongoDB is easy to install
MongoDB supports various programming languages: RUBY, PYTHON, JAVA, C++, PHP, C# and other languages
Support for replication and failover
Third, the operation of the database
create database
Syntax: use database name
If the database exists, enter the database, if it does not exist, create the database
The created database does not exist in the list, it can be displayed after inserting data in the database
delete database
Syntax: db.dropDatabase()
in that database, delete that database
View all databases
Syntax: show dbs
View the database currently in use
Syntax: db or db.getName()
Disconnect
Syntax: exit
Clone the database from the specified host
Syntax: db.cloneDatabase()
Show current database status
Syntax: db.stats()
Current database version
Syntax: db.bersion()
View command api
Syntax: help
4. User operation
Add a user: db.addUser(username)
Set the password: db.addUser (username, password, whether it is readable), if it is readable and writable, true is readable
Show current users: show users
Remove user: db.removeUser(username)
Five, error message operation
Query error information history: db.getPrevError()
Clear error history information: db.reetError()
Sixth, the operation of the collection
View collections under the current database
Syntax: show collections
Create collection 1: db.createCollection("collection name")
eg:db.createCollection("user")
Create collection 2: db.collection name.insert(data)
eg:db.user.insert({name:"Jone",age:12,address"beijing",isDelete:0})
1 method just creates a collection, but there is no data in the collection. 2 Method creates a collection while adding a piece of data to the collection
delete collection
Syntax: db.collectionname.drop()