Among them,nodejs remote connection MySQL database
First, the opening analysis
This is an extended knowledge article because database operations are used in the following article, so today it is (MongoDB module).
(1), introduction
MongoDB is a database based on distributed file storage. Written by the C + + language. Designed to provide scalable, high-performance data storage solutions for Web applications.
MongoDB is a high-performance, open-source, modeless document-based database that is a popular one in the current NoSQL database.
MongoDB is a product between a relational database and a non-relational database, and is the most versatile and most like relational database in a non-relational database. The data structure he supports is very loose and is a JSON-like Bjson format, so you can store more complex data types. MONGO's biggest feature is that the query language he supports is very powerful, and its syntax is a bit like an object-oriented query language that almost implements most of the functionality of a relational database single-table query, and also supports indexing of data.
The traditional relational database is usually composed of three hierarchical concepts of database, table, record, and MongoDB is made up of database, collection (collection), Three levels of document objects.
MongoDB is for tables in relational databases, but there is no concept of columns, rows, and relationships in the collection, which embodies the nature of pattern freedom.
(2), features
It is characterized by high performance, easy to deploy, easy to use, and easy to store data. The main features are:
1) for collection storage, easy to store the object type of data.
2) Mode freedom.
3) Support dynamic query.
4) full index support, including internal objects.
5) Support query.
6) Support replication and recovery.
7) Use efficient binary data storage, including large objects (such as video, etc.).
8) automatically handles fragmentation to support scalability at the cloud level.
9) support multiple languages such as ruby,python,java,c++,php,c#.
10) The file storage format is Bson (a JSON extension).
11) can be accessed via the network.
First, when starting the MONGO database based on the previous article,
Type the following command in the Shell command window: "Use BB" (used command toggles the current database, if the database does not exist, a new one is created first).
Type the following command in the Shell command window: "Db.users.insert ({" Name ":" Bigbear "," Password ":" 12345678 "})", (this command inserts a piece of data into the Users collection, If the collection users do not exist, a new one is created before the data is inserted, and the parameters are passed in JSON format. Type the following command in the Shell command window: "Db.users.find ()" (Displays all data documents under the Users collection), such as:
Note the "_id" in the figure, and the system automatically assigns a unique primary key _id to each record.
All right! Basic function enough, and later if additional operations need to be added gradually, because space is limited mainly said Nodejs operation MongoDB, so temporarily.
Second, then enter the section that operates the database with Nodejs
varMongoDB = require ("MongoDB") ; varServer =NewMongodb. Server ("localhost",27017, {auto_reconnect:true }) ; varconn =NewMongodb. Db ("wly", server,{safe:true }) ; Conn.Open (function (error,db) {if(Error)Throwerror; Db.collection ("Users", {safe:true},function (err,collection) {if(ERR)Throwerr; Collection.find (). ToArray (function (e,docs) {if(e)Throwe; Console.log (Docs); }) ; }) ; }) ;
Results such as:
Nodejs Learning Notes MongoDB module