Python——串連MongoDB

來源:互聯網
上載者:User

標籤:for   abc   int   .so   div   cal   tar   驗證   個數   

建立與MongoDB之間的串連:官方文檔

#coding:utf-8import pymongoclient = pymongo.MongoClient(‘127.0.0.1‘,27017)     # 建立與MongoDB的串連#有使用者名稱和密碼時:pymongo.MongoClient(‘mongodb://使用者名稱:密碼@localhost:27017/基於哪個資料庫進行驗證的‘)db = client.xingedb     # 切換使用的資料庫# 增# db.t1.insert_one({‘name‘:‘abc‘,‘age‘:18})# insert_more# 改# db.t1.update_one({‘name‘:‘abc‘},{‘$set‘:{‘name‘:‘123‘}})# update_more# 刪# db.t1.delete_one({‘name‘:‘123‘})# delete_more# 查# cursor = db.t1.find({‘age‘:{‘$gt‘:17}})     # 返回一個遊標對象# find_one## 顯示方法1:# for i in cursor:#     print(i)## 方法2:# cursor.next()# cursor.next()# cursor.next()# sort,skip,limit方法## cursor = db.t1.find({‘age‘:{‘$gt‘:17}}).sort(‘_id‘,-1).limit(1).skip(1)## for i in cursor:#     print(i)# count方法# print(db.t1.count())

 

Python——串連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.