MAC下用brew安裝mongodb

1.安裝sql

brew install mongodb

2.啓動命令mongo,出現箭頭>說明已經啓動成功mongodb

mongo
➜  workspace mongo
MongoDB shell version: 3.2.8
connecting to: test
>

3.簡單的使用shell

➜  workspace mongo
MongoDB shell version: 3.2.8
connecting to: test
> show dbs;  //查詢庫
local  0.000GB
mongo  0.000GB
> show collections; //查詢表
> use myDbs;   //創建一個名爲myDbs的數據庫,當這個庫存在時則是切換到這個數據庫中去
switched to db myDbs
> db.dropDatabase();  
{ "ok" : 1 }
> show dbs;
local  0.000GB
mongo  0.000GB
> use myDbs;
switched to db myDbs
> show dbs;
local  0.000GB
mongo  0.000GB
> show collections;
> db.myTable.insert({name:'hf',age:20});  //在mongodb中在插入數據時即建立了改表,此時建立的是名爲myTable的數據表
WriteResult({ "nInserted" : 1 })
> show collections;  //查詢表
myTable
> db.myTable.update({name:'hf'},{$set:{age:25}}) //修改
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.myTable.insert({name:'hhh',age:12});//插入
WriteResult({ "nInserted" : 1 })
> db.myTable.find();  //查詢myTable表的全部數據
{ "_id" : ObjectId("5a01160ed78cb73b1908e4bd"), "name" : "hf", "age" : 25 }
{ "_id" : ObjectId("5a011695d78cb73b1908e4be"), "name" : "hhh", "age" : 12 }
> db.myTable.find().sort({age:1})  //根據age升序
{ "_id" : ObjectId("5a011695d78cb73b1908e4be"), "name" : "hhh", "age" : 12 }
{ "_id" : ObjectId("5a01160ed78cb73b1908e4bd"), "name" : "hf", "age" : 25 }
> db.myTable.find().count()    //查詢表myTable的個數
2
> db.myTable.remove({name:'hhh'})     //刪除
WriteResult({ "nRemoved" : 1 })
>

4.打開客戶端發現,已經建立了一個庫名爲myDbs,表名爲myTable的信息數據庫

相關文章
相關標籤/搜索