mongodb學習總結(一)

來源:互聯網
上載者:User

標籤:mongodb筆記

關於mogodb資料庫的預設設定:
1.連接埠預設設定為:270172.資料庫檔案存放位置預設為:c:/data/db,建議修改為其它磁碟位置,必須在磁碟的根目錄建立data/db檔案夾3.mongodb資料庫的預設日誌記錄方式是重寫即覆蓋的方式,建議使用追加的方式寫日誌:mongod --logpath "d:/data/log/mongodb.log" --logappend
mongo shell操作命令:1.串連mongoDB資料庫
mongo --host hostname/ip --port 27017 [databaseName]舉例:mongo --host 172.0.0.1 --port 27017 mydbs
2.集合操作
db.student.drop();//刪除student這個集合
3.文檔操作
重點:瞭解$inc/$set/$unset/$push/$pop/upsert修改器//往student集合裡面插入文檔db.student.insert({"name":"zhangsan"});//查詢文檔使用find();db.student.find();//更新id=58d4ccd4126ab1e4ca76aa73的文檔,修改或者新增其name索引值對db.student.update({ "_id" : ObjectId("58d4ccd4126ab1e4ca76aa73") },{"$set":{"name":"xiaoming"}});//修改文檔使用update()db.student.update({"name":"xiaoming"},{"$set":{"age":23}});db.student.update({"name":"xiaoming"},{"$set":{"name":"成龍"}});結果:{ "_id" : ObjectId("58d4ccd4126ab1e4ca76aa73"), "name" : "成龍", "age" : 23 }//查詢文檔時格式化文檔 db.student.find().pretty();                                  {    "_id" : ObjectId("58d4ccd4126ab1e4ca76aa73"),     "name" : "xiaoming",     "age" : 23 }//刪除文檔文法:db.collection.remove(條件,{justOne: <boolean>,writeConcern: <document>})query :(可選)刪除的文檔的條件。justOne : (可選)如果設為 true 或 1,則只刪除一個文檔。writeConcern :(可選)拋出異常的層級。舉例:db.student.remove({"name":"成龍"},{"justOne":true,"writeConcern":true});
4.條件操作符
$lt(<),$gt(>),$gte(>=),$lte(<=)
5.mongodb模糊查詢
db.student.find({"name":{"$regex":"zhangsa*","$options":"i"}});

結果: {"_id" : ObjectId("58d4da0a126ab1e4ca76aa74"), "name":"zhangsan"}

db.student.insert({"name":"成龍","age":23,"adress":"北京"}); db.student.find({name:{$regex:"成",$options:"i"}});

結果: {"_id" : ObjectId("58d508b109d615ae79c96930"), "name" : "成龍", "age" : 23, "adress" : "北京" }

mongo --host 172.0.0.1 --port 27017 mydbsdb.student.find({"name": {$regex: ‘成龍‘, $options:‘i‘}});db.test_info.find({"tname": {$regex:/成龍./i}});

本文出自 “我的技術部落格” 部落格,請務必保留此出處http://zhufangmin.blog.51cto.com/10913615/1910306

mongodb學習總結(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.