MonGo--- installation and its basic operation
1. Install the Mongo database:
The latest version officially available at the time of release of this article is 1.6.5, which will be used in this tutorial unless otherwise stated.
Step 1: download the installation package: official download address ← Click here, if it is a win system, pay attention to the 64-bit or 32-bit version, please choose the correct version.
Step 2: create a new directory "D:\ MongoDB", extract the downloaded installation package, find all the .exe files in the bin directory, and copy them to the directory you just created.
Step 3: create a new "data" folder under the "D:\ MongoDB" directory, which will serve as the root folder for data storage.
Configure the Mongo server:
Open a CMD window and enter the command as follows:
> d:
> cd D:\ MongoDB
> mongod-- dbpath D:\ MongoDB\ data
Enter: http://localhost:27017/ in the browser, and you can see the following prompt:
You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number
2. Basic operations:
Create\ use database:
> use mongotest
Switched to db mongotest
Display the data sheet:
> show tables
Insert data:
> item= {"Key": "1", "text": "wokao", "number": 3}
{"Key": "1", "text": "wokao", "number": 3}
> db.wang.insert (item)
Query data:
> db.wang.find ()
{"_ id": ObjectId ("52c7812912eae9cca2c31826"), "Key": "1", "text": "wokao", "number": 3}
> item= {"Key": "1", "text": "wokao"}
{"Key": "1", "text": "wokao"}
> db.wang.insert (item)
> db.wang.find ()
{"_ id": ObjectId ("52c7812912eae9cca2c31826"), "Key": "1", "text": "wokao", "number": 3}
{"_ id": ObjectId ("52c7814912eae9cca2c31827"), "Key": "1", "text": "wokao"}
> show tables
System.indexes
Wang
> db.system.indexes.find ()
{"v": 1, "key": {"_ id": 1}, "ns": "mongotest.wang", "name": "_ id_"}
Data deletion:
> db.wang.remove ({"_ id": ObjectId ("52c7812912eae9cca2c31826")})
> db.wang.find ()
{"_ id": ObjectId ("52c7814912eae9cca2c31827"), "Key": "1", "text": "wokao"}
Data modification:
> db.wang.find ()
{"_ id": ObjectId ("52c7814912eae9cca2c31827"), "Key": "1", "text": "wokao"}
> var t=db.wang.findone ({"Key": "1"})
Sat Jan 04 11 Property 42 findone' of object mongotest.wang is not a function 29.671 TypeError:
> var t=db.wang.findOne ({"Key": "1"})
> t.text= "wo shi ni yeyebooks!"
Wo shi ni yeye!!
> db.wang.update ({"Key": "1"}, t)
> db.wang.find ()
{"_ id": ObjectId ("52c7814912eae9cca2c31827"), "Key": "1", "text": "wo shi ni yeyebirds!"}