howdyai / botkit-storage-mongo

A MongoDB storage driver for Botkit
MIT License
54 stars 42 forks source link

Error: slash in host identifier #41

Closed JimLynchCodes closed 5 years ago

JimLynchCodes commented 5 years ago

to repo:

(node:28411) UnhandledPromiseRejectionWarning: Error: Error: slash in host identifier
    at /Users/jameslynch/Git-Projects/Kate-From-HR/chatbot-slack-starter-kate/node_modules/botkit-storage-mongo/src/index.js:24:13
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
(node:28411) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:28411) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

botkit-storage-mongo: 1.0.6 node -v: 8.16.0

JimLynchCodes commented 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?

JimLynchCodes commented 5 years ago

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"
amoungui commented 4 years ago

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