close

MogoDB 就是  依照 Json 建立的 DB

例如 :
在 linux shell 建立 DB 只要用 use test_db 就建立了  test_db 這 DB

[root@test ~]# mongo
MongoDB shell version: 2.6.12
connecting to: test
Server has startup warnings:
2017-02-23T11:07:32.432+0800 [initandlisten]
2017-02-23T11:07:32.432+0800 [initandlisten] ** WARNING: Readahead for /var/lib/mongo is set to 4096KB
2017-02-23T11:07:32.432+0800 [initandlisten] **          We suggest setting it to 256KB (512 sectors) or less
2017-02-23T11:07:32.432+0800 [initandlisten] **          http://dochub.mongodb.org/core/readahead
>  use test_db
switched to db test_db

用 db.students.insert 插入及創建table 資訊

db.students.insert({name:"Mary",age:22,contacts:[{address:{city:"taipe",stree: "Nanj st."},phone:["222334"]}],phone:["44115566","22331122"]})

換成這樣 ...是不是很像 json 格式 :
 

db.students.insert 
(
{
name:"Mary", 
age:22, 
contacts:
        [
        {
        address:
                {
                city:"taipe",
                stree: "Nanj st."
                },
        phone:["222334"]
        }
        ],
phone:[
        "44115566",
        "22331122"
      ]
}
)



建立一個 user可連這 DB

> use test_db
switched to db test_db
> db.createUser({user:"chio", pwd:"chio1234", roles: ["readWrite"] } )
Successfully added user: { "user" : "chio", "roles" : [ "readWrite" ] }
> show users
{
        "_id" : "test_db.chio",
        "user" : "chio",
        "db" : "test_db",
        "roles" : [
                {
                        "role" : "readWrite",
                        "db" : "test_db"
                }
        ]
}

 

用 Robomongo 連進去 就可看到資訊了 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 echochio 的頭像
    echochio

    echochio

    echochio 發表在 痞客邦 留言(0) 人氣()