Official website article, compare SQL and MongoDB
http://docs.mongodb.org/manual/reference/sql-comparison/
DB--Displays the currently used library
Show DBS--Display all libraries
Use DB
Show Collections--Show all tables in the current database
Db.testData.find ()--After selecting the database to manipulate, the DB represents the current database object, TestData represents the data table, and in MONGO table is called collection. The Find () function returns all records (record), and a record in MONGO is called document. If the returned data record is very large by more than 20, the default will only return the first 20, to press "it" (iterate) to continue to display the following 20 records.
Db.testData.insert ()--insert data
Db.data.find ({"_id": "3"})--Find the specified record
Db.testData.findOne ()
Db.testData.find (). Limit (3)
The language style of MONGO's shell-manipulation interaction window is JavaScript syntax, such as:
j = {name: "MONGO"}k = {x:3}db.testdata.insert (j) Db.testData.insert (k)
Indicates that two records were inserted.
{"_id": ObjectId ("4c2209f9f3924d31102bd84a"), "name": "MONGO"} {"_id": ObjectId ("4c2209fef3924d31102bd84b"), "X": 3}
_ID is a unique value in a table, and if not specified, the default system assigns a record a unique _id, or you can specify _id:
> testdate={"_id": "3", "isp_id": "1000314", "IP": "58.177.249.38", "Request_url": "\/bruce\/laiye\/", " Referer ": null," _REF ": null," User_agent ":" mozilla\/5.0 (macintosh; intel mac os x 10.9; rv:31.0) gecko\/20100101 firefox\/31.0 "}{ " _id " : " 3 ", "isp_id" : "1000314", "IP" : "58.177.249.38 ", " Request_url " : "/bruce/laiye/", " Referer " : null, "_ref" : null, "User_agent" : " mozilla/5.0 (macintosh; intel mac os x 10.9; rv:31.0) Gecko/20100101 firefox/31.0 "}> db.data.insert (testdate) writeresult ({ " ninserted " : 1 }) > db.data.find ({"_id" : "3"}) { "_id" : "3", "isp_id" : "1000314", "IP" : " 58.177.249.38 ", " Request_url " : "/bruce/laiye/", " Referer " : null, " _ref " : null, "User_agent" : "mozilla/5.0 (Macintosh; intel mac os x 10.9; rv:31.0) gecko/20100101 firefox/31.0 " }
JavaScript syntax
Use the loop to quickly insert 25 records for (var i = 1; i <=; i++) Db.testData.insert ({x:i})//Output all records var c = Db.testData.find () while (c . Hasnext ()) Printjson (C.next ())//Find specific results var c = db.testData.find () Printjson (c [4])//result {"_id": ObjectId ("51a7dc7b2c Acf40b79990bea ")," X ": 5}//can also write function in the Operation window, and then call directly!! Cow b!! First define the InsertData function InsertData (dbName, colname, num) {var col = db.getsiblingdb (dbName). GetCollection (colname); for (i = 0; i < num; i++) {Col.insert ({x:i}); } print (Col.count ());} Call InsertData ("test", "TestData", 400)
This article is from the "Home Circle Exchange Study" blog, please be sure to keep this source http://brucetam.blog.51cto.com/1863614/1540035