About MongoDB
MongoDB is a document-based non-relational database (NoSQL), for example:
{"Foo":3, "greeting": "hello,world!"}
and case-sensitive, key value unique, non-repeatable, documents can be nested, key-value pairs are ordered
Collection
1, set is a set of documents
2, the document is similar to the row in the relational library
3, set similar to the table in the relational library
4, the collection of documents without a fixed structure (and the difference between the relational database)
Naming of collections
1. Cannot be an empty string
2. Cannot contain the \ s character (null character)
3. You cannot use the prefix of system.
4, the proposal does not contain the reserved word "$"
5. Splitting subsets of different namespaces (for example: blog.users)
Database
1. Multiple documents make up a collection, multiple collections make up a database
2. One instance can host multiple databases
3, each database has independent permissions
4. Reserved database name (admin,local,config)
Command line Operation MongoDB
Refer to the Novice tutorial
The \mongodb\server\3.4\bin enters the command-line window and then knocks MONGO into the MongoDB service, displaying all the databases
> show dbs;
Use a database (it will be created automatically if it does not exist)
> use database name;
Inserting data
Write Data
> = { name:'Jhon', age :+, ' sex ': ' Male "}
Inserting data
> db. database name. Insert (Stu)
Querying data
> db. database name. FIND ()
Update data
>Stu_obj=Db.students.findOne () {"_id": ObjectId ("5a9a01c5b1489e70f3a89a0c"), "name": "Jhon", "Age":
+, "sex": "Male"}>Stu_obj.name="Jackchen" Jackchen>Db.students.Update({name: "Jhon"},stu_obj) Writeresult ({"nmatched":1, "nupserted":0, "nmodified":1 })>Db.students.findOne () {"_id": ObjectId ("5a9a01c5b1489e70f3a89a0c"), "name": "Jackchen", "Age" : +, "sex": "Male"}
When updating the data, the second parameter in update completely replaces the previous parameter, so if the second parameter has only {name: "* *"}, the original data will be deleted
If you want to update multiple data, you can use the Updatemany
Summary: Updating data in this way is quite cumbersome and can be used with modifiers
Delete data
It turns out to be three data:
>, "Sex": "Male"}
Delete one of the following:
>1 })>, "sex": "Male"}
Delete all:
>2 })> db.students.find ()>
Python Operation MongoDB Database