python3 : เชื่อมต่อ mongoDb
step 1 ติดตั้งด้วยคำสั่ง
py -m pip install pymongo
step2 ลองรัน Code ดังนี้ (ใช้ฐานข้อมูลจากตัวอย่างก่อนหน้านี้)
from pymongo import MongoClient
# pprint library is used to make the output look more pretty
from pprint import pprint
# connect to MongoDB, change the << MONGODB URL >> to reflect your own connection string
client = MongoClient('mongodb://localhost:27017')
db=client.NetFlick
# Issue the serverStatus command and print the results
#serverStatusResult=db.command("serverStatus")
result = db.movies.find()
#print(serverStatusResult)
for r in result:
print (r)
py -m pip install pymongo
step2 ลองรัน Code ดังนี้ (ใช้ฐานข้อมูลจากตัวอย่างก่อนหน้านี้)
from pymongo import MongoClient
# pprint library is used to make the output look more pretty
from pprint import pprint
# connect to MongoDB, change the << MONGODB URL >> to reflect your own connection string
client = MongoClient('mongodb://localhost:27017')
db=client.NetFlick
# Issue the serverStatus command and print the results
#serverStatusResult=db.command("serverStatus")
result = db.movies.find()
#print(serverStatusResult)
for r in result:
print (r)
ความคิดเห็น
แสดงความคิดเห็น