First, collection (table of corresponding database) 1, view all the collections in the current library
Show collections
2. Create new collection explicitly
Db.createcollection ("user")
Implicitly-Created
Db. user. Insert ({name: "Zhangsan"})
3. Deleting a Collection
Db. user. Dorpcollection ()
Ii. documents (rows in the corresponding database) 1, new (insert, save, Insertone/insertmany) 1.1, New with Insert method
Db. user. Insert ({name: "Zhangsan", Age:+, Sex: "Boy"})
or define the variables and save the variables first.
Lisi={name: "Lisi", Age:+, Sex: "Girl", Phone: "13999999999"}
Db. user. Insert (Lisi)
1.2. Use the Save method to add
Db. user. Save ({name: "Xiaoli", Age:, Sex: "Girl"})
or define the variables and save the variables first.
Wangwu={name: "Wangwu", Age:+, Sex: "Boy", Email: "XXX@xx. com"}
Db. user. Save (WANGWU)
1.3. Use Insertone (single INSERT, equivalent to insert) and Insertmany (BULK Insert)
Db. User <optional params>-insert A document, optional parameters are:w, Wtimeout, Jdb. User [objects] <optional params>-Insert Multiple documents, optional parameters Are:w, Wtimeout, J
2. By deleting
Db. user. Dorp ()
3, change
4. Check
MongoDB's common operations on collections (tables) and data