Skip to content

[novice question] I'm hitting an error while running the schema file in MongoDB with Nodejs #1134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tapudp opened this issue Mar 1, 2018 · 2 comments

Comments

@Tapudp
Copy link

Tapudp commented Mar 1, 2018

  • Node.js Version: v8.9.2
  • OS: WIndows 10 (Version 1709 (OS Build 16299.192))
  • Scope (install, code, runtime, meta, other?):
  • Module (and version) (if relevant):

# I'm following Academind's playlist on creating Node.js Shopping Cart and in the Video #4 "Seeding Data" I've created the models for it and then trying to create product-seeder.js file as follows:

var Product = require('../models/product');

var mongoose = require('mongoose');

mongoose.connect('localhost:27017/shopping');

var products = [
    new Product({
    imagePath: 'https://upload.wikimedia.org/wikipedia/en/5/5e/Gothiccover.png',
    title: 'Gothic Video Game',
    description: 'Awesome Game!!!',
    price: 10
    }),
    new Product({
        and it's details
    }),
];
var done = 0;
for (var i = 0; i < products.length; i++) {
    products[i].save();
    done++;
    if(done === products.length){
        exit();
    }
}

function exit(){
    mongoose.disconnect();
};

error regarding the mongodb server

(node:2316) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: URI does not have hostname, domain name and tld
(node:2316) [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.

my package.json has these modules:

{
  "name": "shopping-cart",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.18.2",
    "cookie-parser": "~1.4.3",
    "debug": "~2.6.9",
    "express": "~4.15.5",
    "express-handlebars": "^3.0.0",
    "hbs": "~4.0.1",
    "mongoose": "^5.0.7",
    "morgan": "~1.9.0",
    "serve-favicon": "~2.4.5"
  }
}

@gireeshpunathil
Copy link
Member

assuming your db name is shopping, the connection string should be one of:

  • mongoose.connect('mongodb://localhost/shopping')
  • mongoose.connect('localhost', 'shopping')
  • mongoose.connect('mongodb://localhost:27017/shopping)

@gireeshpunathil
Copy link
Member

closing as answered, please re-open if it is still outstanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants