throw new Error('Mongoose is not connected');
up vote
2
down vote
favorite
So I'm trying to use the mongoose-gridfs module with express but I get the following error when I try to run my express server.
Error: Mongoose is not connected
at new GridFSStorage (C:UsersBARMANDocumentsCodeszubis-martnode
_modulesmongoose-gridfslibstorage.js:43:11)
at module.exports (C:UsersBARMANDocumentsCodeszubis-martnode_mo
dulesmongoose-gridfslibstorage.js:472:18)
at Object.<anonymous> (C:UsersBARMANDocumentsCodeszubis-martrou
tesusers.js:24:42)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:UsersBARMANDocumentsCodeszubis-martser
ver.js:15:15)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
Here's where I think the problem is from ##
const express = require('express');
const bcrypt = require('bcryptjs');
const fs = require('fs');
const mongoose = require('mongoose');
const multer = require('multer');
const passport = require('passport');
const config = require('../config/database');
mongoose.connect(config.database,
useNewUrlParser: true
);
let conn = mongoose.connection;
conn.once('open', () =>
console.log('Database File Upload Connection Established Successfully.');
);
conn.on('error', (err) =>
console.log('File Connection Error... ' + err);
);
const gridfs = require('mongoose-gridfs')(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
My Connection string if okay but I just can't seem to figure it out. Really need help please. Thanks Guys!
javascript node.js mongodb mongoose
New contributor
Barman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
2
down vote
favorite
So I'm trying to use the mongoose-gridfs module with express but I get the following error when I try to run my express server.
Error: Mongoose is not connected
at new GridFSStorage (C:UsersBARMANDocumentsCodeszubis-martnode
_modulesmongoose-gridfslibstorage.js:43:11)
at module.exports (C:UsersBARMANDocumentsCodeszubis-martnode_mo
dulesmongoose-gridfslibstorage.js:472:18)
at Object.<anonymous> (C:UsersBARMANDocumentsCodeszubis-martrou
tesusers.js:24:42)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:UsersBARMANDocumentsCodeszubis-martser
ver.js:15:15)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
Here's where I think the problem is from ##
const express = require('express');
const bcrypt = require('bcryptjs');
const fs = require('fs');
const mongoose = require('mongoose');
const multer = require('multer');
const passport = require('passport');
const config = require('../config/database');
mongoose.connect(config.database,
useNewUrlParser: true
);
let conn = mongoose.connection;
conn.once('open', () =>
console.log('Database File Upload Connection Established Successfully.');
);
conn.on('error', (err) =>
console.log('File Connection Error... ' + err);
);
const gridfs = require('mongoose-gridfs')(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
My Connection string if okay but I just can't seem to figure it out. Really need help please. Thanks Guys!
javascript node.js mongodb mongoose
New contributor
Barman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
So I'm trying to use the mongoose-gridfs module with express but I get the following error when I try to run my express server.
Error: Mongoose is not connected
at new GridFSStorage (C:UsersBARMANDocumentsCodeszubis-martnode
_modulesmongoose-gridfslibstorage.js:43:11)
at module.exports (C:UsersBARMANDocumentsCodeszubis-martnode_mo
dulesmongoose-gridfslibstorage.js:472:18)
at Object.<anonymous> (C:UsersBARMANDocumentsCodeszubis-martrou
tesusers.js:24:42)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:UsersBARMANDocumentsCodeszubis-martser
ver.js:15:15)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
Here's where I think the problem is from ##
const express = require('express');
const bcrypt = require('bcryptjs');
const fs = require('fs');
const mongoose = require('mongoose');
const multer = require('multer');
const passport = require('passport');
const config = require('../config/database');
mongoose.connect(config.database,
useNewUrlParser: true
);
let conn = mongoose.connection;
conn.once('open', () =>
console.log('Database File Upload Connection Established Successfully.');
);
conn.on('error', (err) =>
console.log('File Connection Error... ' + err);
);
const gridfs = require('mongoose-gridfs')(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
My Connection string if okay but I just can't seem to figure it out. Really need help please. Thanks Guys!
javascript node.js mongodb mongoose
New contributor
Barman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
So I'm trying to use the mongoose-gridfs module with express but I get the following error when I try to run my express server.
Error: Mongoose is not connected
at new GridFSStorage (C:UsersBARMANDocumentsCodeszubis-martnode
_modulesmongoose-gridfslibstorage.js:43:11)
at module.exports (C:UsersBARMANDocumentsCodeszubis-martnode_mo
dulesmongoose-gridfslibstorage.js:472:18)
at Object.<anonymous> (C:UsersBARMANDocumentsCodeszubis-martrou
tesusers.js:24:42)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:UsersBARMANDocumentsCodeszubis-martser
ver.js:15:15)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
Here's where I think the problem is from ##
const express = require('express');
const bcrypt = require('bcryptjs');
const fs = require('fs');
const mongoose = require('mongoose');
const multer = require('multer');
const passport = require('passport');
const config = require('../config/database');
mongoose.connect(config.database,
useNewUrlParser: true
);
let conn = mongoose.connection;
conn.once('open', () =>
console.log('Database File Upload Connection Established Successfully.');
);
conn.on('error', (err) =>
console.log('File Connection Error... ' + err);
);
const gridfs = require('mongoose-gridfs')(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
My Connection string if okay but I just can't seem to figure it out. Really need help please. Thanks Guys!
javascript node.js mongodb mongoose
javascript node.js mongodb mongoose
New contributor
Barman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Barman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Barman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 10 at 12:00
Barman
133
133
New contributor
Barman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Barman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Barman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
You should make sure the connection is opened first then initialize gridfs,
conn.once('open', () =>
global.gridfs = mongooseGridFS(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
);
Thanks it works. But now I'm unable to access the gridfs variable from another block. So how do I access a variable defined with the "global" keyword?
– Barman
2 days ago
add a comment |
up vote
0
down vote
As You may see from trace issue happens when it tries to create GridFSStorage instance and throws error because mongoose is not ready:
Error: Mongoose is not connected
at new GridFSStorage (C:UsersBARMANDocumentsCodeszubis-martnode
_modulesmongoose-gridfslibstorage.js:43:11)
Make sure mongoose connected to db before attaching gridfs.
Here is fix:
const express = require('express');
const bcrypt = require('bcryptjs');
const fs = require('fs');
const mongoose = require('mongoose');
const mongooseGridFS = require('mongoose-gridfs');
const multer = require('multer');
const passport = require('passport');
const config = require('../config/database');
mongoose.connect(config.database,
useNewUrlParser: true
);
let conn = mongoose.connection;
conn.once('open', () =>
console.log('Database File Upload Connection Established Successfully.');
global.gridfs = mongooseGridFS(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
);
conn.on('error', (err) =>
console.log('File Connection Error... ' + err);
);
P.S. I've read mongoose-gridfs manual which insantiated exactly as in Your question which is incorrect.
Since in code source at line #43 it immediately checks for connection state - which does tells that documentation is not correct.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You should make sure the connection is opened first then initialize gridfs,
conn.once('open', () =>
global.gridfs = mongooseGridFS(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
);
Thanks it works. But now I'm unable to access the gridfs variable from another block. So how do I access a variable defined with the "global" keyword?
– Barman
2 days ago
add a comment |
up vote
0
down vote
accepted
You should make sure the connection is opened first then initialize gridfs,
conn.once('open', () =>
global.gridfs = mongooseGridFS(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
);
Thanks it works. But now I'm unable to access the gridfs variable from another block. So how do I access a variable defined with the "global" keyword?
– Barman
2 days ago
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You should make sure the connection is opened first then initialize gridfs,
conn.once('open', () =>
global.gridfs = mongooseGridFS(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
);
You should make sure the connection is opened first then initialize gridfs,
conn.once('open', () =>
global.gridfs = mongooseGridFS(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
);
answered Nov 10 at 12:11
Sletheren
1,495315
1,495315
Thanks it works. But now I'm unable to access the gridfs variable from another block. So how do I access a variable defined with the "global" keyword?
– Barman
2 days ago
add a comment |
Thanks it works. But now I'm unable to access the gridfs variable from another block. So how do I access a variable defined with the "global" keyword?
– Barman
2 days ago
Thanks it works. But now I'm unable to access the gridfs variable from another block. So how do I access a variable defined with the "global" keyword?
– Barman
2 days ago
Thanks it works. But now I'm unable to access the gridfs variable from another block. So how do I access a variable defined with the "global" keyword?
– Barman
2 days ago
add a comment |
up vote
0
down vote
As You may see from trace issue happens when it tries to create GridFSStorage instance and throws error because mongoose is not ready:
Error: Mongoose is not connected
at new GridFSStorage (C:UsersBARMANDocumentsCodeszubis-martnode
_modulesmongoose-gridfslibstorage.js:43:11)
Make sure mongoose connected to db before attaching gridfs.
Here is fix:
const express = require('express');
const bcrypt = require('bcryptjs');
const fs = require('fs');
const mongoose = require('mongoose');
const mongooseGridFS = require('mongoose-gridfs');
const multer = require('multer');
const passport = require('passport');
const config = require('../config/database');
mongoose.connect(config.database,
useNewUrlParser: true
);
let conn = mongoose.connection;
conn.once('open', () =>
console.log('Database File Upload Connection Established Successfully.');
global.gridfs = mongooseGridFS(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
);
conn.on('error', (err) =>
console.log('File Connection Error... ' + err);
);
P.S. I've read mongoose-gridfs manual which insantiated exactly as in Your question which is incorrect.
Since in code source at line #43 it immediately checks for connection state - which does tells that documentation is not correct.
add a comment |
up vote
0
down vote
As You may see from trace issue happens when it tries to create GridFSStorage instance and throws error because mongoose is not ready:
Error: Mongoose is not connected
at new GridFSStorage (C:UsersBARMANDocumentsCodeszubis-martnode
_modulesmongoose-gridfslibstorage.js:43:11)
Make sure mongoose connected to db before attaching gridfs.
Here is fix:
const express = require('express');
const bcrypt = require('bcryptjs');
const fs = require('fs');
const mongoose = require('mongoose');
const mongooseGridFS = require('mongoose-gridfs');
const multer = require('multer');
const passport = require('passport');
const config = require('../config/database');
mongoose.connect(config.database,
useNewUrlParser: true
);
let conn = mongoose.connection;
conn.once('open', () =>
console.log('Database File Upload Connection Established Successfully.');
global.gridfs = mongooseGridFS(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
);
conn.on('error', (err) =>
console.log('File Connection Error... ' + err);
);
P.S. I've read mongoose-gridfs manual which insantiated exactly as in Your question which is incorrect.
Since in code source at line #43 it immediately checks for connection state - which does tells that documentation is not correct.
add a comment |
up vote
0
down vote
up vote
0
down vote
As You may see from trace issue happens when it tries to create GridFSStorage instance and throws error because mongoose is not ready:
Error: Mongoose is not connected
at new GridFSStorage (C:UsersBARMANDocumentsCodeszubis-martnode
_modulesmongoose-gridfslibstorage.js:43:11)
Make sure mongoose connected to db before attaching gridfs.
Here is fix:
const express = require('express');
const bcrypt = require('bcryptjs');
const fs = require('fs');
const mongoose = require('mongoose');
const mongooseGridFS = require('mongoose-gridfs');
const multer = require('multer');
const passport = require('passport');
const config = require('../config/database');
mongoose.connect(config.database,
useNewUrlParser: true
);
let conn = mongoose.connection;
conn.once('open', () =>
console.log('Database File Upload Connection Established Successfully.');
global.gridfs = mongooseGridFS(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
);
conn.on('error', (err) =>
console.log('File Connection Error... ' + err);
);
P.S. I've read mongoose-gridfs manual which insantiated exactly as in Your question which is incorrect.
Since in code source at line #43 it immediately checks for connection state - which does tells that documentation is not correct.
As You may see from trace issue happens when it tries to create GridFSStorage instance and throws error because mongoose is not ready:
Error: Mongoose is not connected
at new GridFSStorage (C:UsersBARMANDocumentsCodeszubis-martnode
_modulesmongoose-gridfslibstorage.js:43:11)
Make sure mongoose connected to db before attaching gridfs.
Here is fix:
const express = require('express');
const bcrypt = require('bcryptjs');
const fs = require('fs');
const mongoose = require('mongoose');
const mongooseGridFS = require('mongoose-gridfs');
const multer = require('multer');
const passport = require('passport');
const config = require('../config/database');
mongoose.connect(config.database,
useNewUrlParser: true
);
let conn = mongoose.connection;
conn.once('open', () =>
console.log('Database File Upload Connection Established Successfully.');
global.gridfs = mongooseGridFS(
collection: 'images',
model: 'Image',
mongooseConnection: conn
);
);
conn.on('error', (err) =>
console.log('File Connection Error... ' + err);
);
P.S. I've read mongoose-gridfs manual which insantiated exactly as in Your question which is incorrect.
Since in code source at line #43 it immediately checks for connection state - which does tells that documentation is not correct.
edited Nov 10 at 12:28
answered Nov 10 at 12:08
num8er
10.8k21738
10.8k21738
add a comment |
add a comment |
Barman is a new contributor. Be nice, and check out our Code of Conduct.
Barman is a new contributor. Be nice, and check out our Code of Conduct.
Barman is a new contributor. Be nice, and check out our Code of Conduct.
Barman is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238727%2fthrow-new-errormongoose-is-not-connected%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password