试图让GridFSBucket用于猫鼬,但是即使花了2天也没有运气。我收到有关GridStore的警告,因此想到使用GridFSBucket就像我们使用猫鼬一样,因此提到了link,但相同的代码对我不起作用。
以下是我尝试的代码-
var express = require('express');
var gridfsService = express.Router();
var mongoose = require('mongoose');
const conn = mongoose.createConnection('mongodb://user:password@127.0.0.1:27017/dbname');
const gridFsBucket = new mongoose.mongo.GridFSBucket(conn.db);
我得到的错误是-
_chunksCollection: db.collection(options.bucketName + '.chunks'),
^
TypeError: Cannot read property 'collection' of undefined
at new GridFSBucket (d:\Projects\myapp\node_modules\mongoose\node_modules\mongodb\lib\gridfs-stream\index.js:50:27)
at Object.<anonymous> (d:\Projects\myapp\services\myapp.service.js:6:22)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous>
我正在使用以下版本-Nodejs-8.11.2 Mongoose- 5.0.0 mongodb-4.0.4