Fork me on github

python操作mongodb数据库

1.连接

import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
print(myclient.list_database_names())

2.查询

查询全部

for row in myAuthors.find():
    print(row)
displayName Fay Chang 

按条件查询:

pub_papers下的publishedDate中含有relational databases
pub_papers下的description中含有relational databases
import regex
r1 = mycol.find( {
   "pub_papers.publishedDate":{ "$regex": "relational databases"  } 
    })
r2 = mycol.find( {
   "pub_papers.description":{ "$regex": "relational databases"  } 
    })
for row in r1:
    print(row)

for row in r2:
    print(row)

 

posted @ 2024-10-23 16:42  我の前端日记  阅读(3)  评论(0编辑  收藏  举报
Copyright © 2021 LinCangHai
Powered by .NET 5.0 on Kubernetes