时间:2021-07-01 10:21:17 帮助过:21人阅读
gridfs操作也比较简单:
const
mongodb
=
require(‘mongodb‘);
const
fs
=
require(‘fs‘);
const
url
=
‘mongodb://127.0.0.1:27017‘;
let
client
=
await
mongodb.MongoClient.connect(url, { useNewUrlParser: true });
let
db
=
client.db(‘test‘);
var
bucket
=
new
mongodb.GridFSBucket(db, { chunkSizeBytes: 1024
*
1024, bucketName: ‘image‘ });
await
fs.createReadStream(‘./3.jpg‘).pipe(bucket.openUploadStream(‘3.jpg‘));
同时,觉得现在VS Code写Node程序已经非常给力了,不仅调试功能非常好用,智能提示也非常棒,以后Node程序就用它了。
?
NodeJS下的Mongodb操作
标签:ack sync insert one 127.0.0.1 pip color 图片 mongod