close

使用python進行MongoDB的連接,算是後端吧

總而言之工作很難找,所以開始自己做一些專案累積作品集,應該是一輩子找不到工作了吧XD

我使用的是pymongo,網路上相關的資料也蠻多的

這邊展示的是自己使用的程式碼

# import
from pymongo import MongoClient
from bson.objectid import ObjectId #這東西透過ObjectID去尋找的時候會用到

# connection
conn = MongoClient("localhost") # 如果你只想連本機端的server你可以忽略,遠端的url填入: mongodb://<user_name>:<user_password>@ds<xxxxxx>.mlab.com:<xxxxx>/<database_name>
db = conn.ntut # db指定為連結中的ntut資料庫
collection = db.students  # collection指定為db中的students集合

# test if connection success
print(collection.stats)
# 如果沒有error,你就連線成功了。

 

相關文章:MongoDB 筆記


arrow
arrow
    文章標籤
    python MongoDB 後端
    全站熱搜

    低階ㄇㄋ 發表在 痞客邦 留言(0) 人氣()