MONGO DB one of the Learning notes: MongoDB early acquaintance

Source: Internet
Author: User


Official website article, compare SQL and MongoDB

http://docs.mongodb.org/manual/reference/sql-comparison/


    1. DB--Displays the currently used library

    2. Show DBS--Display all libraries

    3. Use DB

    4. Show Collections--Show all tables in the current database

    5. 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.

    6. Db.testData.insert ()--insert data

    7. Db.data.find ({"_id": "3"})--Find the specified record

    8. Db.testData.findOne ()

    9. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.