After the installation of Mongodb , no matter what else, first cool, and then a little bit of detail behind the said.
(1) : Open service : C:\mongodb\bin>mongod--dbpath=c:\mongodb\data
(2): Open client:C:\mongodb\bin>mongo 127.0.0.1:27017
(3): View all databases:Show DBS
(4): using command: use can be used to switch the database, if the switch database does not exist, will create a new database
As above: If the user database exists, it will switch to the user database. If it does not exist, the user database will be created before switching to the user database. But one thing to note: This is the data
Library and Is not really created, only when the data is inserted, the database is actually created, that is, if you create only an empty database without inserting data, then this database is invalid.
After the database is created, basic additions and deletions are started, but before that, it is important to illustrate a small thing: the following
(1) There is no concept of table in MongoDB, which is different from relational database.
(2) MongoDB is mainly composed of three parts, the document, the collection (Collection), and the database.
(3) document is equivalent to a row of records in a database table; Collection corresponds to a table in a relational database and consists of multiple document; Many collection are combined to form the database
The specific relationship between document, collection, and database can be expressed as:
Well, with these preparation knowledge, we began to formally delete and change the operation.
(1): Insert operation:
Description: DB: Indicates the current database;
Persons: Represents a collection for the current database, if it does not exist, is created, if present, with the original;
Insert (): This method is used to insert the document. The inserted data is in Bson format (an extension of JSON)
The above form is represented in the relational database: A table named persons was created, and two records were inserted.
(2): query: Use the Find () method to query out all records. Note: _id is the default for the database to add, the role is equivalent to the primary key in the relational database, to ensure the uniqueness of the data.
(3): Modify: Use the update () method
Description of the modified statement db.persons.update ({"Name": "Zhangsan"}, {$set: {"name": "Wangwu"}}):
(a) In order to understand, it can be understood as such an SQL statement: Update persons set Name= ' Wangwu ' where name= ' Zhangsan ';
(b) The update () method can be interpreted as follows: Update ({Query condition},{update}); (Follow the detailed instructions, first try to say it again)
(4): Delete: Use the Remove () method, such as: Db.persons.remove ({delete condition}), if not write the condition is all delete
Description: Db.persons.remove ({"Name": "Lisi"}): Deleted Name=lisi document, if written as Db.persons.remove () deletes all records
OK, the most basic additions and deletions to explore the experience is finished. Finally, we introduce a few basic commands:
(1):Show Collections : View all the collection in the data;
Where system.indexes is automatically generated by the system
(2): Delete collection: For example Delete Persons collection: Db.persons.drop ();
(3): Delete database: Db.dropdatabase ();
Experience complete
MongoDB (ii): MongoDB Initial experience: basic use