Mongo数据库
MongoDB安装及配置
数据库启动服务
mongod --dbpath D:\Euclid_Jie\DBdataIt looks like you are trying to access MongoDB over HTTP on the native driver port.use admin db.shutdownServer()
数据库创建及写入
最后更新于
mongod --dbpath D:\Euclid_Jie\DBdataIt looks like you are trying to access MongoDB over HTTP on the native driver port.use admin
db.shutdownServer()最后更新于
import pymongo
def MongoClient(DBName, collectionName):
# 连接数据库
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient[DBName] # 数据库名称
mycol = mydb[collectionName] # 集合(表)
return mycol
# 返回一个数据表
mycol = MongoClient("ZhiHu", '11月知乎舆情')mycol.insert_one(document) # 其中document为json格式的数据
mycol.insert_many(document) # 写入多条mycol.distinct("_id") # 获取数据表的所有id,返回格式为list
mycol.find_one({'_id': id}) # 根据指定条件查询,返回数据表的其中一条数据,格式为jsonmycol.update_one({'_id': id}, {"$set": {'comment': comment}}) # $set为一种更新方法idList = mycol.distinct("_id", {'天眼查Num': "天眼查无法查询", 'Url': {'$exists': False}})db.cols.find({"name":{"$ne":null}})db.cols.find({"name":{$regex:"\d"}})
db.cols..find({"name":{$regex:"[0-9]"}})