I'm attempting to authenticate my gridfs object that is used in mongoose/mongodb for uploading image files. I connect to my database like so:
mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
auth: { authSource: 'admin' },
user: username,
pass: password,
});
const conn = mongoose.connection.on('connected', () => {
initgfs(conn.db);
});
where my gridfs config is:
module.exports.initgfs = (url) => {
gfs = new mongoose.mongo.GridFSBucket(url, {
bucketName: // ...
});
return gfs;
}
However when I attempt to utilize GFS to perform a write operation in mongo, I get the following error:
MongoError: command insert requires authentication
at Connection.<anonymous> (/app/node_modules/mongodb/lib/core/connection/pool.js:450:61)
at Connection.emit (events.js:209:13)
at processMessage (/app/node_modules/mongodb/lib/core/connection/connection.js:384:10)
at Socket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connection.js:553:15)
at Socket.emit (events.js:209:13)
at addChunk (_stream_readable.js:305:12)
at readableAddChunk (_stream_readable.js:286:11)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead (internal/stream_base_commons.js:166:17)
when all my other writes/reads from my mongo db that do not utilize gfs are not receiving any auth errors. Any help is appreciated, thanks!
question from:
https://stackoverflow.com/questions/66052022/authenicating-a-gridfs-object 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…