python-mongodb-select
## python-mongo-connector ## connection
import pymongo
import datetime
from pymongo import MongoClient
cnx=MongoClient('localhost', 27017)
#### Show available databases ####
print (cnx.database_names())
db=cnx['mypymongdb'] #### DatabaseName ####
print (db.name)
print (db.profiling_level())
collection=db.abc ## = foxpro use tableName
## mongo-insert ##
#row = {"_id": str(datetime.datetime.now()), "author": "Mike", "text": "Hello PyMongo!", "tags": ["mongodb", "python", "pymongo"], "date": datetime.datetime.utcnow()}
row = {
"author": "Mike",
"text": "Hello PyMongo!",
"tags": ["mongodb", "python", "pymongo"],
"date": datetime.datetime.utcnow()
}
## mongodb-use difference table(posts) to update =>db.posts
dbHandler=db.posts
record=dbHandler.insert(row)
row = {
"authors": "Mike", ## it will be difference field
"text": "Hello PyMongo!",
"tags": ["mongodb", "python", "pymongo"],
"date": datetime.datetime.utcnow()
}
dbHandler=db.posts
record=dbHandler.insert(row)
## mongodb-reccount => dbHandler.count() ##
print("There are " + str(dbHandler.count()) + " records in the collection (aka Table). Details are:")
## mongodb-select ##
for queryset in dbHandler.find():
print( queryset )
## mongodb-close ##
db.logout()
沒有留言:
張貼留言