赞
踩
use grid
db.fs.files.find()
{
"_id" : ObjectId("5cbd1aab2ee99b20d42fb744"),
"chunkSize" : NumberInt(261120),
"uploadDate" : ISODate("2019-04-22T09:36:49.556+08:00"), // 存储时间
"length" : NumberInt(91222751), // 文件大小
"md5" : "54ca1997408bbae6814ffe0bb501006a",
"filename" : "C:\\Users\\Administrator\\Desktop\\aaa.pptx"
}
db.fs.chunks.find()
{
"_id" : ObjectId("5cbd1aab2ee99b20d42fb745"),
"files_id" : ObjectId("5cbd1aab2ee99b20d42fb744"), // fs.files中对应文件的_id
"n" : NumberInt(0), // 块数
"data" : BinData(0,"UEsDBAoAAAAAA... more 261096 bytes") // 二进制块,每个块大约32KB
},
{
"_id" : ObjectId("5cbd1aab2ee99b20d42fb746"),
"files_id" : ObjectId("5cbd1aab2ee99b20d42fb744"),
"n" : NumberInt(1),
"data" : BinData(0,"hHrztljLZnS3k... more 261096 bytes ")
},
import pymongo import gridfs coon = pymongo.MongoClient("127.0.0.1", 27017) # 创建数据库连接 db = coon.grid # 切换到大文件数据库 fs = gridfs.GridFS(db) # 获取gridFS对象 files = fs.find() # 可迭代对象,每个对象为一个文件 for file in files: with open(file.filename, "wb") as f: # file.filename为原文件的存储路径 while True: # 循环读写操作 data = file.read(64) if not data: break f.write(data) coon.close()
var cursor = db.student.find(); // 创建游标
cursor.next() // 使用游标
{
"_id" : ObjectId("5cb95eb8da176022385c1a84"),
"stu_name" : "陈飞扬",
"stu_ID" : "2019023105",
"stu_age" : 18,
"stu_hobby" : [
"篮球",
"足球",
"吉他"
],
"msg" : "aeqwe 喜欢"
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。