You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 12, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 12, 2025. It is now read-only.
mongoose and gridfs-locking-stream interaction #131
my experience is i was using gridfs-stream with multer-gridfs-storage
for some reason mongoose:"^5.0" has issues with gridfs-stream when making connections and when i managed to make the connections multer-gridfs-stroage failed. so whatI resorted to was to use two mongoose versions in my application. At the end of the day i had different connections one to my GridFS and another to my mongoDatabase ; therefor i went on to use V5.0 for my mongodb and v4. for my GridFS. on how to install same packages of different version follow this https://gist.github.com/mnpenner/c46a5eff34cfa91f361a8b3baa249a10
Using the db object instead of the connection resolved my issue.
So instead of this:
var gfs;
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log("Connected!")
var mongoDriver = mongoose.mongo;
gfs = new Gridfs(db, mongoDriver);
});
To this
var gfs;
var connection = mongoose.connection;
connection.on('error', console.error.bind(console, 'connection error:'));
connection.once('open', function() {
console.log("Connected!")
var mongoDriver = mongoose.mongo;
gfs = new Gridfs(connection.db, mongoDriver);
});
Using the db object instead of the connection resolved my issue.
So instead of this:
var gfs;
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log("Connected!")
var mongoDriver = mongoose.mongo;
gfs = new Gridfs(db, mongoDriver);
});
To this
var gfs;
var connection = mongoose.connection;
connection.on('error', console.error.bind(console, 'connection error:'));
connection.once('open', function() {
console.log("Connected!")
var mongoDriver = mongoose.mongo;
gfs = new Gridfs(connection.db, mongoDriver);
});
Using the db object instead of the connection resolved my issue.
So instead of this:
var gfs;
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log("Connected!")
var mongoDriver = mongoose.mongo;
gfs = new Gridfs(db, mongoDriver);
});
To this
var gfs;
var connection = mongoose.connection;
connection.on('error', console.error.bind(console, 'connection error:'));
connection.once('open', function() {
console.log("Connected!")
var mongoDriver = mongoose.mongo;
gfs = new Gridfs(connection.db, mongoDriver);
});
Activity
arn-the-long-beard commentedon Apr 13, 2018
Hello.
I also get the same error
Then if I replace with
``javascript
const conn = mongoose.connection
var Grid = require('gridfs-stream');
Grid.mongo = mongoose.mongo
const gfs = Grid(conn)
``
Then I get
I am using :
Best regards,
Arn
deresegetachew commentedon May 2, 2018
my experience is i was using gridfs-stream with multer-gridfs-storage
for some reason mongoose:"^5.0" has issues with gridfs-stream when making connections and when i managed to make the connections multer-gridfs-stroage failed. so whatI resorted to was to use two mongoose versions in my application. At the end of the day i had different connections one to my GridFS and another to my mongoDatabase ; therefor i went on to use V5.0 for my mongodb and v4. for my GridFS. on how to install same packages of different version follow this https://gist.github.com/mnpenner/c46a5eff34cfa91f361a8b3baa249a10
ldevalbray commentedon Oct 13, 2018
Hey I have the same issue ...
Any solution found ? I would like to avoid @deresegetachew 's one ;)
stelapo commentedon Dec 13, 2018
Hey I have the same issue ...
Any solution found ?
zenbert5 commentedon Jan 24, 2019
for reference i have encountered this. two difference instances of this happened with my code --
mongo server isn't accessible for whatever reason
modified my connection code -->
const conn = mongoose.createConnection('your URI');
var gfs;
conn.once('open', () => {
gfs = Grid(conn.db, mongoose.mongo);
})
from const conn = mongoose.connection(...)
"express": "^4.16.4",
"gridfs-stream": "^1.1.1",
"mongoose": "^5.4.5",
mongo DB v4.02
Good luck
kuzdogan commentedon Oct 3, 2019
Refer to here: #56
Using the
dbobject instead of theconnectionresolved my issue.So instead of this:
To this
MZeeshan373 commentedon Feb 23, 2021
Thanks @kuzdogan This resolved my issue .
Chris-QIU commentedon Jun 19, 2021
@kuzdogan Thank you very much, this works.