mongo DB基本操作

  1. 基本命令

root@8a5fa5a8f6b8:/usr/bin# /usr/bin/mongo

show dbs;
use db_sys;
show tables;
db.users.find(); # select * from users ;


https://www.cnblogs.com/TankMa/archive/2011/06/08/2074947.html

  1. python下使用

myclient = pymongo.MongoClient('mongodb://x.x.x.x:27017/')
 
dblist = myclient.list_database_names()
# print(dblist)

db_sys = myclient['sys']
# print(db_sys)

model_info = db_sys['users'].find_one()
# print(model_info)

model_info = db_sysdog['users'].find()  # 返回的是<class 'pymongo.cursor.Cursor'> 
print(dir(model_info))  # 有__next__,__iter__方法
for i in model_info:
      print(i)


db_sys.list_collection_names()  #show tables;
posted @ 2021-01-18 13:44  该显示昵称已被使用了  阅读(51)  评论(0编辑  收藏  举报