mongodb的一些簡單操作

來源:互聯網
上載者:User

標籤:open   enumerate   環境   baidu   cli   建立   int   txt   個數   

# import pymongo   #匯入pymongo庫
# client = pymongo.MongoClient(‘localhost‘,27017) 串連python與mongo資料庫(localhost是本地)
# walden = client[‘walden‘]給資料庫起一個名字左邊是在python中的名字,右邊中括弧裡是在資料庫環境中的名字
# sheet_line = walden[‘sheet_line‘]建立一個資料庫的sheet
# path = ‘D:\BaiduNetdiskDownload\walden.txt‘
# with open(path,‘r‘) as f:
# lines = f.readlines() 讀取檔案中的每一行
# for index,line in enumerate(lines):enumerate函數是迴圈資料的位置和資料
# data ={
# ‘index‘:index,
# ‘line‘:line,
# ‘words‘:len(line.split())
#
# }
# sheet_line.insert_one(data) 將data的資料裝入資料庫
# $lt/$lte/$gt/$gte/$ne,依次等價於</<=/>/>=/!=
# for item in sheet_line.find({‘words‘:{‘$lt‘:5}}):
# print(item)

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.