Closed JimLynchCodes closed 5 years ago
also tried with this simpler uri, but same error: mongodb://AdminUser:xxxxxxxxxx@cluster0-xahr1.mongodb.net/db:27017
Is this the correct format for the mongo uri botkit is expecting? Do I need to open some special permissions on my mongodb (other than my local ip address) to allow the connection?
I was getting kind of a generic network error, but this may help someone else.
I am using Mongo Atlas, and when I added these extra params to the uri it worked!
MONGO_URI="mongodb://AdminUser:xxxxxxxxxx@cluster9-shard-09-09-asdf.mongodb.net:27017/db?ssl=true&replicaSet=Cluster9-shard-0&authSource=admin"
Hello, I'm developing a node.js project with mongodb, express, but I get this error when I start the server:
MongoDB connection error: Error: slash in host identifier [nodemon] app crashed - waiting for file changes before starting ...
this is my files: mongoose.js file:
const { mongo, env } = require('./vars');
// set mongoose Promise to Bluebird
mongoose.Promise = Promise;
// Exit application on error
mongoose.connection.on('error', (err) => {
console.error(`MongoDB connection error: ${err}`);
process.exit(-1);
});
// print mongoose logs in dev env
if (env === 'development') {
mongoose.set('debug', true);
}
/**
* Connect to mongo db
*
* @returns {object} Mongoose connection
* @public
*/
exports.connect = () => {
mongoose.connect(mongo.uri, {
keepAlive: 1,
useMongoClient: true,
});
return mongoose.connection;
};
my var.js file:
const path = require('path');
// import .env variables
require('dotenv-safe').load({
path: path.join(__dirname, '../../.env'),
sample: path.join(__dirname, '../../.env.example'),
});
module.exports = {
env: process.env.NODE_ENV,
port: process.env.PORT,
jwtSecret: process.env.JWT_SECRET,
jwtExpirationInterval: process.env.JWT_EXPIRATION_MINUTES,
masterAccount: process.env.MASTER_ACCOUNT_NUMBER,
masterAccountPassword: process.env.MASTER_ACCOUNT_PASSWORD,
mongo: {
uri: process.env.NODE_ENV === 'test'
? process.env.MONGO_URI_TESTS
: process.env.MONGO_URI,
},
logs: process.env.NODE_ENV === 'production' ? 'combined' : 'dev',
};
the index.js file:
Promise = require('bluebird'); // eslint-disable-line no-global-assign
const { port, env } = require('./config/vars');
const app = require('./config/express');
const mongoose = require('./config/mongoose');
// open mongoose connection
mongoose.connect();
// listen to requests
app.listen(port, () => console.info(`server started on port ${port} (${env})`));
/**
* Exports express
* @public
*/
module.exports = app;
thanks for you help
to repo:
set MONGO_URI to the uri of my mongodb (mongodb://AdminUser:xxxxxxxxxxx@cluster0-shard-00-00-dsfdgs.mongodb.net:27017,cluster0-shard-00-01-sdfgf.mongodb.net:27017,cluster0-shard-00-02-sdfgd.mongodb.net:27017/test?replicaSet=Cluster0-shard-0)
run botkit starter
go to /login and click authorize app
server crashes with this error:
botkit-storage-mongo: 1.0.6 node -v: 8.16.0