mongodb 的基本操作

by pxz


发布于: 2014-03-10 所属分类: 服务器 数据库 mongodb 标签:  526


<h3 id="h3--mongodb"><a name="启动mongodb" class="reference-link"></a><span class="header-link octicon octicon-link"></span>启动mongodb</h3><p>全新安装好mongodb后, 在 c盘新建data文件夹, 进入data文件夹再新建db文件夹, 然后来到命令行 执行 mongod 启动 mongodb服务</p> <h3 id="h3-u63D2u5165u6570u636E"><a name="插入数据" class="reference-link"></a><span class="header-link octicon octicon-link"></span>插入数据</h3><p>>db.member.insert({“username”:”zsg”, “passwd”:”123”})</p> <h3 id="h3-u5220u9664u6570u636E"><a name="删除数据" class="reference-link"></a><span class="header-link octicon octicon-link"></span>删除数据</h3><p>>db.member.remove({“username”:”zsg”})</p> <h3 id="h3-u66F4u65B0u6570u636E"><a name="更新数据" class="reference-link"></a><span class="header-link octicon octicon-link"></span>更新数据</h3><p>>db.member.update({“username”:”zsg”}, {“username”:”zsg”, “passwd”:”456”})</p> <h3 id="h3--member-"><a name="删除member表" class="reference-link"></a><span class="header-link octicon octicon-link"></span>删除member表</h3><p>> db.member.drop()</p> <h3 id="h3--member-"><a name="删除member表" class="reference-link"></a><span class="header-link octicon octicon-link"></span>删除member表</h3><p>> db.member.drop()</p> <h3 id="h3-mongodb-"><a name="mongodb的增删改查操作试验" class="reference-link"></a><span class="header-link octicon octicon-link"></span>mongodb的增删改查操作试验</h3><p>> show dbs<br>local 0.03125GB<br>> use soho<br>switched to db soho<br>> show dbs<br>local 0.03125GB<br>> show collections<br>> db<br>soho<br>> show collections<br>> item = {“username”:”admin”, “passwd”:”123”}<br>{ “username” : “admin”, “passwd” : “123” }<br>> item<br>{ “username” : “admin”, “passwd” : “123” }<br>> db.member.insert(item)<br>> show collections<br>member<br>system.indexes<br>> show dbs<br>local 0.03125GB<br>soho 0.0625GB<br>> db.member.find()<br>{ “_id” : ObjectId(“531dd1cba438f3d32079e446”), “username” : “admin”, “passwd” :<br>“123” }<br>> db.member.insert({“username”:”zsg”,”passwd”:”123”,”email”:”<a href="mailto:sg@qq.com">sg@qq.com</a>”})<br>> db.member.find()<br>{ “_id” : ObjectId(“531dd1cba438f3d32079e446”), “username” : “admin”, “passwd” :<br>“123” }<br>{ “_id” : ObjectId(“531dd232a438f3d32079e447”), “username” : “zsg”, “passwd” : “<br>123”, “email” : “<a href="mailto:sg@qq.com">sg@qq.com</a>” }<br>> db.member.findOne({“username”:”zsg”})<br>{<br>“_id” : ObjectId(“531dd232a438f3d32079e447”),<br>“username” : “zsg”,<br>“passwd” : “123”,<br>“email” : “<a href="mailto:sg@qq.com">sg@qq.com</a>”<br>}<br>> db.member.findOne({“passwd”:”123”})<br>{<br>“_id” : ObjectId(“531dd1cba438f3d32079e446”),<br>“username” : “admin”,<br>“passwd” : “123”<br>}<br>> db.member.find({“passwd”:”123”})<br>{ “_id” : ObjectId(“531dd1cba438f3d32079e446”), “username” : “admin”, “passwd” :<br>“123” }<br>{ “_id” : ObjectId(“531dd232a438f3d32079e447”), “username” : “zsg”, “passwd” : “<br>123”, “email” : “<a href="mailto:sg@qq.com">sg@qq.com</a>” }<br>> db.member.find({“passwd”:”1235”})<br>><br>> tmp = db.member.findOne({“passwd”:”123”})<br>{<br>“_id” : ObjectId(“531dd1cba438f3d32079e446”),<br>“username” : “admin”,<br>“passwd” : “123”<br>}<br>> tmp<br>{<br>“_id” : ObjectId(“531dd1cba438f3d32079e446”),<br>“username” : “admin”,<br>“passwd” : “123”<br>}<br>> tmp.passwd = “456”<br>456<br>> tmp<br>{<br>“_id” : ObjectId(“531dd1cba438f3d32079e446”),<br>“username” : “admin”,<br>“passwd” : “456”<br>}<br>> db.member.update({“username”:”admin”}, tmp)<br>> db.member.find()<br>{ “_id” : ObjectId(“531dd1cba438f3d32079e446”), “username” : “admin”, “passwd” :<br>“456” }<br>{ “_id” : ObjectId(“531dd232a438f3d32079e447”), “username” : “zsg”, “passwd” : “<br>123”, “email” : “<a href="mailto:sg@qq.com">sg@qq.com</a>” }<br>></p>

发表评论

暂无评论

搜索
用户登陆