Querying an existing database
>show DBS
2. Create a database, you need to create a collection this Coucay creates
>use MyDB
3. View Collections
>show Collections or >show tables
4. Create a document and insert data
>db.userinfo.insert ({_id:1,name: "Xiaoming"})
5. Bulk Insert document, Shell is not support bulk INSERT, want to complete bulk insert can be used in MongoDB application driver or shell for loop
>for (var i =0;i<10;i++) {.. Db.userInfo.insert ({name:i}):}
6. View the contents of the document
>db.userinfo.find ()
7.save operation, the save operation and the insert operation differ in the case of encountering _id in the same situation
Save operation completed
Insert will error
> Db.userInfo.insert ({_id:1,name: "Xiaoming"}) Writeresult ({"ninserted": 1}) > Db.userInfo.insert ({_id:1,name: "Xiaocang"}) Writeresult ({"ninserted": 0, "Writeerror": {"code": 11000, "errmsg": "Insertdocument:: Caused by:: 11000 E 11000 duplicate key error index:foobar.userinfo.$_id_ dup key: {: 1.0} "}}" > Db.userInfo.save ({_id:1,name: "Xiaocang" }) Writeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1})
8. Delete all the data in the list, the collection and index will not be deleted
> Db.userInfo.remove ({}) Writeresult ({"nremoved": 1}) > Db.userInfo.find () > Show Collectionssystem.indexesuserinfo
9. Delete by condition
Db. [Documentname].remove ({})
Delete a record in the collection with name equal to Xiaoming
Db.userInfo.remove ({name: "Xiaoming"})
This article is from a "little progress every Day" blog, make sure to keep this source http://08jw3.blog.51cto.com/998816/1675975
MongoDB Note 1 (Basic operations, additions and deletions)