One of the mongodb Learning Notes: a preliminary understanding of mongodb
Articles on the official website, comparing SQL and mongodb
Http://docs.mongodb.org/manual/reference/sql-comparison/
Db-displays the libraries currently in use
Show dbs-shows all libraries
Use db
Show collections-displays all tables in the current database
Db.testData.find ()-after selecting the database to operate on, 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 one record in mongo is called document. If the returned data records are very large and more than 20, only the first 20 records will be returned by default. 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 operation 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 are inserted.
{"_ id": ObjectId ("4c2209f9f3924d31102bd84a"), "name": "mongo"} {"_ id": ObjectId ("4c2209fef3924d31102bd84b"), "x": 3}
_ id is the only value in a table. If it is not specified, the default system assigns a record and 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