<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>pymongo | SDT 攻城獅區</title>
	<atom:link href="https://sdt.hameba.tw/tag/pymongo/feed/" rel="self" type="application/rss+xml" />
	<link>https://sdt.hameba.tw</link>
	<description>由Steven, Der, Ted 三位高級打字員所組成，是三位工程師(攻城獅)所維護的技術分享平台，或許偶爾會分享一些日常，有任何問題或是錯誤的部分，歡迎留言告訴我們！</description>
	<lastBuildDate>Sun, 05 Jan 2020 14:47:12 +0800</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.3</generator>

<image>
	<url>https://sdt.hameba.tw/wp-content/uploads/2020/02/hameba_favicon-150x150.png</url>
	<title>pymongo | SDT 攻城獅區</title>
	<link>https://sdt.hameba.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>python 使用 MongoDB 基本集合(CRUD)</title>
		<link>https://sdt.hameba.tw/452/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-%25e4%25bd%25bf%25e7%2594%25a8-mongodb-%25e5%259f%25ba%25e6%259c%25ac%25e9%259b%2586%25e5%2590%2588crud</link>
				<comments>https://sdt.hameba.tw/452/#respond</comments>
				<pubDate>Sun, 05 Jan 2020 14:45:29 +0000</pubDate>
		<dc:creator><![CDATA[Li Der]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[pymongo]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=452</guid>
				<description><![CDATA[<p>先前介紹了使用pymongo來連線MongoDB，以及驗證身份來做連線。 這次來說明基本的集合(CRUD)。  &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/452/" class="more-link">閱讀全文<span class="screen-reader-text">〈python 使用 MongoDB 基本集合(CRUD)〉</span></a></p>
The post <a href="https://sdt.hameba.tw/452/">python 使用 MongoDB 基本集合(CRUD)</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>先前介紹了使用pymongo來連線MongoDB，以及驗證身份來做連線。</p>
<p>這次來說明基本的集合(CRUD)。</p>
<p><span id="more-452"></span></p>
<ul>
<li><strong>起手式</strong></li>
</ul>
<p></p><pre class="crayon-plain-tag">from pymongo import MongoClient

client = MongoClient('YOUR_DB_IP', 27017)
db = client[MONGO_DB]
db.authenticate(MONGO_USER_NAME, MONGO_USER_PWD)
collection = db[MONGO_COLLETION]</pre><p>&nbsp;</p>
<ul>
<li><strong>查詢資料｜單筆(find_one)｜全部(find)</strong></li>
</ul>
<p></p><pre class="crayon-plain-tag">collection.find_one({'x': 1}) #查詢符合資料的第一筆</pre><p></p><pre class="crayon-plain-tag">collection.find({'x': 1}) #查詢符合資料的全部</pre><p>&nbsp;</p>
<ul>
<li><strong>查詢個數｜(<span class="n">count_documents</span>)</strong></li>
</ul>
<div>
<pre class="crayon-plain-tag">collection.count_documents({'x': 1}) #查詢符合資料的個數</pre>
</div>
<p>&nbsp;</p>
<ul>
<li><strong>寫入資料｜單筆(insert_one)｜多筆(insert_many)</strong></li>
</ul>
<p></p><pre class="crayon-plain-tag">collection.insert_one({'x': 1}) #一次新增一筆資料</pre><p></p><pre class="crayon-plain-tag">collection.insert_many([{'x': 1},{'x': 1}]) #一次新增多筆資料</pre><p>&nbsp;</p>
<ul>
<li><strong>修改資料｜單筆(update_one)｜多筆(update_many)</strong></li>
</ul>
<p></p><pre class="crayon-plain-tag">collection.update_one({'x': 1}, {'$set': {'x': 2}}) #修改符合資料的第一筆</pre><p></p><pre class="crayon-plain-tag">collection.update_many({'x': 1}, {'$set': {'x': 2}}) #修改符合資料的全部</pre><p>&nbsp;</p>
<ul>
<li><strong>刪除資料｜單筆(delete_one)｜多筆(delete_many)</strong></li>
</ul>
<p></p><pre class="crayon-plain-tag">collection.delete_one({'x': 1}) #刪除符合的第一筆資料</pre><p></p><pre class="crayon-plain-tag">collection.delete_many({'x': 1}) #刪除符合的全部資料</pre><p>&nbsp;</p>
<p>&nbsp;</p>
<p>參考資料：</p>
<ol>
<li><a href="https://api.mongodb.com/python/current/api/pymongo/collection.html">https://api.mongodb.com/python/current/api/pymongo/collection.html</a></li>
<li><a href="https://www.jianshu.com/p/2b176830ca1e">https://www.jianshu.com/p/2b176830ca1e</a></li>
</ol>
<p>&nbsp;</p>The post <a href="https://sdt.hameba.tw/452/">python 使用 MongoDB 基本集合(CRUD)</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/452/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Python 連線 MongoDB 驗證身份</title>
		<link>https://sdt.hameba.tw/385/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-%25e9%2580%25a3%25e7%25b7%259a-mongodb-%25e9%25a9%2597%25e8%25ad%2589%25e8%25ba%25ab%25e4%25bb%25bd</link>
				<comments>https://sdt.hameba.tw/385/#respond</comments>
				<pubDate>Sun, 29 Dec 2019 15:12:04 +0000</pubDate>
		<dc:creator><![CDATA[Li Der]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[authenticate]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[pymongo]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=385</guid>
				<description><![CDATA[<p>上一次有提到  Python 連線 MongoDB ， 這次來補充如果要驗證身份的話，要怎麼處理。 首先在Mo &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/385/" class="more-link">閱讀全文<span class="screen-reader-text">〈Python 連線 MongoDB 驗證身份〉</span></a></p>
The post <a href="https://sdt.hameba.tw/385/">Python 連線 MongoDB 驗證身份</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>上一次有提到  <a href="https://sdt.hameba.tw/367/" target="_blank" rel="noopener noreferrer">Python 連線 MongoDB</a> ，</p>
<p>這次來補充如果要驗證身份的話，要怎麼處理。</p>
<p><span id="more-385"></span></p>
<p>首先在MongoDB建立一個使用者，</p>
<p>設定好使用者名稱、密碼、角色。</p>
<p>再來看一下程式要怎麼調整：</p>
<div>
<div>
<pre class="crayon-plain-tag">client = MongoClient('YOUR_DB_IP', 27017)
db = client[MONGO_DB]
db.authenticate(MONGO_USER_NAME, MONGO_USER_PWD)</pre>
</div>
<p>&nbsp;</p>
</div>
<p>&nbsp;</p>
<p>參考資料：</p>
<p><a href="https://api.mongodb.com/python/current/examples/authentication.html">https://api.mongodb.com/python/current/examples/authentication.html</a></p>The post <a href="https://sdt.hameba.tw/385/">Python 連線 MongoDB 驗證身份</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/385/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Python 連線 MongoDB ( pymongo )</title>
		<link>https://sdt.hameba.tw/367/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-%25e9%2580%25a3%25e7%25b7%259a-mongodb-pymongo</link>
				<comments>https://sdt.hameba.tw/367/#respond</comments>
				<pubDate>Sun, 22 Dec 2019 15:47:12 +0000</pubDate>
		<dc:creator><![CDATA[Li Der]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[pymongo]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=367</guid>
				<description><![CDATA[<p>先安裝好MongoDB， 接下來我們在安裝 pymongo，就可以連線MongoDB了。 先用 pip 安裝  &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/367/" class="more-link">閱讀全文<span class="screen-reader-text">〈Python 連線 MongoDB ( pymongo )〉</span></a></p>
The post <a href="https://sdt.hameba.tw/367/">Python 連線 MongoDB ( pymongo )</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>先安裝好MongoDB，</p>
<p>接下來我們在安裝 pymongo，就可以連線MongoDB了。</p>
<p><span id="more-367"></span></p>
<p>先用 pip 安裝 pymongo</p><pre class="crayon-plain-tag">pip3 install pymongo</pre><p>記得要先import</p><pre class="crayon-plain-tag">from pymongo import MongoClient</pre><p>連線MongoDB</p><pre class="crayon-plain-tag">global collection
client = MongoClient('YOUR_DB_IP', 27017)
db = client[MONGO_DB]
collection = db[MONGO_COLLETION]</pre><p>如何 <a href="https://sdt.hameba.tw/385/" target="_blank" rel="noopener noreferrer">Python 連線 MongoDB 驗證身份</a></p>
<p>&nbsp;</p>
<p>參考資料：</p>
<p><a href="https://www.itread01.com/content/1547079438.html">https://www.itread01.com/content/1547079438.html</a></p>The post <a href="https://sdt.hameba.tw/367/">Python 連線 MongoDB ( pymongo )</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/367/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
	</channel>
</rss>
