\u6587\u6863\u64cd\u4f5c<\/strong><\/div>\n\u6dfb\u52a0\u6587\u6863(\u6570\u636e)<\/p>\n
db.\u96c6\u5408\u540d\u79f0.insert(document)<\/p>\n
\u6bcf\u4e00\u6761\u6570\u636e\uff0c\u5c31\u662f\u4e00\u4e2adocument\uff0c\u5c31\u662f\u4e00\u6761json\u4f8b\uff1adb.student.insert({name:'\u6bdb\u5229', age:18})<\/p>\n
\u6ce8\u610f\u70b9\uff1a<\/p>\n
\u6dfb\u52a0\u6587\u6863\u65f6\uff0c\u5982\u679c\u4e0d\u6307\u5b9a_id\u53c2\u6570 MongoDB\u4f1a\u4e3a\u6587\u6863\u5206\u914d\u4e00\u4e2a\u552f\u4e00\u7684ObjectId<\/p>\n
\u7ed9\u5b9a _id\u4f8b\uff1adb.student.insert({'_id':1, name:'\u6bdb\u5229', age:18})<\/p>\n
\u6dfb\u52a0\u591a\u6761\u6587\u6863<\/p>\n
\r\ndb.student.insert([ \r\n {name:'\u6bdb\u5229, sex:'\u7537', age:18}, \r\n {name:\u2019\u6bdb\u5229\u7684\u7238\u7238', sex:'\u7537', age:47}, \r\n {name:\u2019\u6bdb\u5229\u7684\u59d0\u59d0', sex:'\u5973', age:23}, \r\n {name:\u2019\u6bdb\u5229\u7684\u5988\u5988\u2018, sex:\u2019\u5973', age:44}, \r\n]) \r\n<\/pre>\n\u67e5\u8be2\u6587\u6863(\u6570\u636e)<\/strong><\/div>\ndb.\u96c6\u5408\u540d\u79f0.find([conditions])<\/p>\n
\u67e5\u770b\u96c6\u5408\u4e2d\u5168\u90e8\u6570\u636e\uff1adb.student.find()<\/p>\n
\u683c\u5f0f\u5316\u663e\u793a\uff1adb.student.find().pretty()<\/p>\n
\u67e5\u770b\u6ee1\u8db3\u6761\u4ef6\u7684\u6570\u636e\uff1adb.student.find({name:'\u6bdb\u5229'})<\/p>\n
\u6761\u4ef6\u67e5\u8be2<\/strong><\/div>\nand\u6761\u4ef6 {$and:[{expression1}, {expression1}, ...] }
\nor\u6761\u4ef6 {$or:[{expression1}, {expression1}, ...]
\n}db.student.find({$or:[{$and:[{sex:'\u5973'}, {age:23}]},{$and:[{sex:'\u7537'}, {age:{$gte:18}}]}]})
\n<\/p>\n
\u4fee\u6539\u6587\u6863(\u6570\u636e)<\/strong><\/div>\ndb.\u96c6\u5408\u540d\u79f0.update(, , {multi:})<\/p>\n
\u4fee\u6539\u4e00\u6761\u6570\u636e\uff1adb.student.update({sex:'\u7537'}, {age:20})\u628a\u8868\u4e2d\u7684\u7537\u7684age\u6539\u4e3a20<\/p>\n
\u6307\u5b9a\u5c5e\u6027\u4fee\u6539\uff1a{ $set: {age:20} }db.student.update({name:'\u6bdb\u5229'}, {$set: {age:666, sex: '\u4e0d\u544a\u8bc9\u4f60'}} )<\/p>\n
\u628a\u6bdb\u5229\u7684age\u6539\u4e3a666\uff0csex\u6539\u4e3a\u4e0d\u544a\u8bc9\u4f60<\/p>\n
\u66f4\u65b0\u96c6\u5408\u4e2d\u6240\u6709\u6ee1\u8db3\u6761\u4ef6\u7684\u6587\u6863\uff1a{ multi: true }<\/p>\n
\r\ndb.student.update({sex:'\u7537'}, {$set:{sex:'\u5973'}}, { multi:true} ) \r\n<\/pre>\n\u628a\u6240\u6709\u6309\u7684\u6539\u4e3a\u5973\u7684<\/p>\n
\u5220\u9664\u6587\u6863(\u6570\u636e)<\/strong><\/div>\ndb.\u96c6\u5408\u540d\u79f0.remove(, {justOne:})<\/p>\n
\u5220\u9664\u96c6\u5408\u4e2d\u6240\u6709\u7684\u6587\u6863\uff1adb.student.remove({})
\n\u5220\u9664\u96c6\u5408\u4e2d\u6ee1\u8db3\u6761\u4ef6\u7684\u6240\u6709\u6587\u6863db.student.remove({sex: '\u7537'})
\n\u53ea\u5220\u9664\u96c6\u5408\u4e2d\u6ee1\u8db3\u6761\u4ef6\u7684\u7b2c\u4e00\u6761\u6587\u6863\uff1a{ justOne: true }
\ndb.student.remove({sex:'\u7537'}, { justOne:true} )<\/p>\n
\u5728Python\u7a0b\u5e8f\u4e2d\u64cd\u4f5c<\/strong><\/div>\nMongoDB\u5728 Python \u4e2d\u64cd\u4f5c MongoDB \uff0c\u9700\u8981\u4f7f\u7528 PyMongo \u5e93\uff0c\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1apip3 install pymongo\u3002<\/p>\n
\u8fde\u63a5\u65f6\u9700\u8981\u4f7f\u7528 PyMongo \u5e93\u91cc\u9762\u7684 MongoClient \u6a21\u5757\uff0c\u6709\u4e24\u79cd\u65b9\u5f0f\u53ef\u4ee5\u521b\u5efa\u8fde\u63a5\uff0c\u9ed8\u8ba4\u53ea\u9700\u8981\u4f20\u5165IP\u548c\u7aef\u53e3\u53f7\u5373\u53ef\u3002\u5982\u679c\u6570\u636e\u5e93\u5b58\u5728\u8d26\u53f7\u5bc6\u7801\uff0c\u5219\u9700\u8981\u6307\u5b9a\u8fde\u63a5\u7684\u6570\u636e\u5e93\uff0cMongoDB\u7684\u5916\u7f51IP\u5fc5\u987b\u5f00\u653e\uff0c\u624d\u80fd\u8fde\u63a5\u6210\u529f\u3002<\/p>\n
\r\n>>> from pymongo import MongoClient \r\n>>> client = MongoClient('mongodb:\/\/192.168.92.92:27017') \r\n>>> db = client.school \r\n>>> for student in db.students.find(): \r\n... print('\u59d3\u540d:', student['name']) \r\n<\/pre>\n\u672c\u6587\u5df2\u6536\u5f55 GitHub\uff1ahttps:\/\/github.com\/MaoliRUNsen\/runsenlearnpy100<\/p>\n","protected":false},"excerpt":{"rendered":"
MongoDB\u662f\u4e00\u4e2a\u4ecb\u4e8e\u5173\u7cfb\u578b\u6570\u636e\u5e93\u548c\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93\u4e4b\u95f4\u7684\u4ea7\u54c1\uff0c\u662f\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93\u5f53\u4e2d\u529f\u80fd\u6700\u4e30\u5bcc\uff0c\u6700\u50cf\u5173\u7cfb\u578b\u6570\u636e […]<\/p>\n","protected":false},"author":1898,"featured_media":206238,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[621],"class_list":["post-206209","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-mongodb"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/206209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=206209"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/206209\/revisions"}],"predecessor-version":[{"id":206220,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/206209\/revisions\/206220"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/206238"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=206209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=206209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=206209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}