mongoDB 安裝 和簡單命令,mongodb安裝命令

來源:互聯網
上載者:User

mongoDB 安裝 和簡單命令,mongodb安裝命令


mongo官網  http://www.mongodb.org/downloads

vue工具 下載 http://www.mongovue.com/downloads/


建一個檔案夾,放解壓後的mongo檔案,在建立一個放 指定資料庫 

做一個變數,指定bin

下面檔案夾和路徑可以自訂

mongod --dbpath d:\installSoft\mongoDbDATA

mongo 127.0.0.1:27017/admin


下面是簡單命令

下載mongodb指定路徑datamongod --dbpath e:\mongoDB\mongoDbDATAmongo 127.0.0.1:27017/adminuse dbname  --建立資料庫db.dropDatabase() --刪除show dbs --顯示show collections --顯示集合db.persons.insert({name:"hello"}) --插入資料 db.persons.find()db.persons.update({name:"hello"},{$set:{name:"newh"}})var p=db.persons.findOne()pdb.persons.update(p,{name:"updateV"})db.persons.update({name:"updateV"},{$set:{age:1,name:"newV"}})db.persons.remove({age:1}) --刪除資料db.persons.drop() --刪除 personsdb.help() function insertxx(obj){db.getCollection("dbName").text.insert(obj)}insertxx({name:"hello"})db.getCollection("dbName").find()db.eval("return 'mongodb'")for(var i=0;i<10;i++){ db.pp.insert({name:i})}db.pp.insert({_id:"重複"}) --報錯db.pp.save({_id:"重複"}) --更新db.pp.remove() --集合刪除 索引不會刪除db.system.indexes.find()db.pp.remove({_id:1}) --條件刪除db.docName.update({查詢器},{修改器}) insertOrUpdate --預設false db.docName.update({查詢器},{修改器},true)--批次更新  false更新不儲存,true批量(預設只更新第一條資料)db.pp.update({name:"hello"},{$set:{name:"helloWrold"}},false,true)$set$inc  -- 追加 數字$unset --去掉指定健$push  --汪加數組 db.test.update({_id:1},{$push:{books:["01","02","03"]}}) db.test.update({_id:1},{$pushAll:{books:["01","02","03"]}})$addToSet --如果數組中沒才添加db.test.update({_id:1},{addToSet{books:"hellos"}})$pop -1刪除第一個值  1 刪除最後一個值 1$pull --刪除一個被指定的數值$pullAll db.test.update({_id:1},{$pullAll:{books:["aa","bb"]}})$.在數組對像中修改db.test.update({"books.type":"db"},{$set:{"books.$.author":"liangrui"}})--把有的不加入,沒有的加入  db.test.update({_id:2},{$addToSet:{books:{$each:["js","db"]}}}) --runCommand 只能修改一條婁據    new 返回 pp是更新前的還是更新後的 ps=db.runCommand({   "findAndModify":"test",   "query":{"name":"hello"},   "update":{"$set":{"age":"wwww"}},   "new":true})ps.valuedb.rui.find({},{_id:0,name:1})-- 查詢指定列 {條件}{顯示}  0不顯示m 在>25 <30之間的數()db.rui.find({m:{$gte:25,$lte:30}},{_id:0,name:1})--不等於db.rui.find({name:{$ne:"hello"}},{})--in  在db.rui.find({name:{$in:["hello"]}},{})--nin  不在db.rui.find({name:{$nin:["hello"]}},{})--or  c大於20 或者m大於30的資料db.rui.find({$or:[{c:{$gt:20}},{m:{$gt:30}}]},{})--查詢為null db.rui.find({sex:{$in:[null]}},{_id:0,name:1,sex:2})--正則查詢db.rui.find({name:/ji/i},{_id:0,name:1})--取返db.rui.find({name:{$not:/ji/i}},{_id:0,name:1})--喜歡js 和java書的學生db.rui.find({books:{$all:["js","java"]}},{books:1,_id:0,name:2})--查詢第二本是c++的學生db.rui.find({"books.1":"c++"},{books:1,_id:0,name:2})--查詢指定長度數組$size 它不能與比較查詢符一起使用查詢 出喜歡 的書 數量是4本的學生db.rui.find({books:{$size:3}})--查詢出喜歡的書箱數量大於2本的學生db.rui.update({},{$set:{size:3}},false,true)db.rui.find()--第次加減書的時候 更新sizedb.rui.update({},{$set:{size:3}},false,true)db.rui.update({name:"jim"},{$push:{books:"c"},$inc:{size:1}})--書本==5的db.rui.find({size:4})--查詢jim喜歡書的數量 var jim=db.rui.find({name:"jim"}) while(jim.hasNext()){ obj=jim.next(); print(obj.books.length) }shell 是個js的引擎  要用驅動包$slice  指定數組的內部值 db.rui.find({name:"jim"},{books:{$slice:[1,3]},_id:0}) -1 最後一本書 db.rui.find({name:"jim"},{books:{$slice:-1},_id:0}) --文檔查詢var jim=[         {   school:"k",           score:"a"  },     {   school:"l",           score:"b"  } ,  {   school:"j",           score:"p+"  }  ]db.rui.update({name:"jim"},{$set:{school:jim}})--必須順序一樣,全部指定db.rui.find({school:{school:"k",score:"a"}},{_id:0})--最佳化db.rui.find({"school.score":"a","school.school":"k"},{_id:0,school:1})--$elemMatch解決順序的問題 和 遍曆 全部物件查詢db.rui.find({school:{$elemMatch:{school:"k"}}},{_id:0,school:1})$where  查詢age大於22,喜歡c++ 在k學校上過的學生  db.rui.find({"$where":function(){  //得到查詢結果的每一條文檔  var books=this.books;  //得到文檔中的school對象  var school=this.school;  //如果年紀>=22  if(this.age>22){  var  cjj=null;  //遍曆資料  for(var i=0;i<books.length;i++){   if(books[i]=="c++"){   cjj=books[i];   //如果學校是真   if(school){for(var j=0;j<school.length;j++){//是不是在k學校上學 if(school[j].school=="k"){ //返回真  return true; }}break;   }   }  }  }  }})  ---分頁    db.rui.find({},{_id:0,name:1}).limit(5)  db.rui.find({},{_id:0,name:1}).limit(5).skip(5)  db.rui.find({},{_id:0,name:1,age:2}).limit(5).skip(5).sort({age:1})    db.rui.find({},{_id:0,name:1,age:2}).limit(5).skip(5).sort({name:-1})


相關文章

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.