MongoDB is a collection-oriented document database, unlike relational databases where tables, columns, rows, and MongoDB databases are composed of a series of documents. Here to introduce the concept of MongoDB and simple operation.
1, the following list of common relational database and MongoDB database simple conceptual differences:
2, MongoDB simple operation
(1) After starting the MongoDB database, use the command MONGO, as shown below, to connect to the test database by default.
MongoDB Shell version:3.2.6
Connecting To:test
Using the command show DBS, you can view all the databases and see only one local data, but the test database does not exist, and only when you build the collection and insert data into the collection will you actually build the table.
Common commands:
Show DBS shows all the databases
Switch the use database name to one of the data
Show collections displays all collections in the current database
Db. Collection name. Find () query all data under a collection in the current database
Db. Collection name. Insert ({"Key": "Value", "Key": "Value" ...}) to add data to a collection in the current database
Db. Collection name. Drop () Delete a collection
Db.dropdatabase () deletes the current database
Now let's use the above command to do a simple example: re-establish a data zyhtest and create a new collection student in Zyhtest and insert the data into the student.
> Use zyhtest
switched to db zyhtest
> Db.student.insert ({"Name": "Zhangsan", "Age":})
Writeresult ({"ninserted": 1})
> Show dbs
0.000GB
zyhtest 0.000GB
> Show Collections
student
> Db.student.find () c10/>{"_id": ObjectId ("5745b8a08dfa492b66e7d397"), "name": "Zhangsan", "Age":
> Db.student.drop ()
t Rue
> Show dbs local
0.000GB
> Db.student.insert ({"Name": "Zhangsan", "Age":)
Writeresult ({"ninserted": 1})
> show dbs local
0.000GB
zyhtest 0.000GB
> Show collections< C21/>student
> Db.dropdatabase ()
{"Dropped": "Zyhtest", "OK": 1}
> Show DBS
When inserting data, a primary key "_id" is automatically added
The above content is small to introduce the MongoDB Quick Start Note (ii) of the MONGODB concept and simple operation of the relevant knowledge, I hope to help you!