homePage.create is not working. i think my problem is here
"mongoose.connect('mongo://localhost:27017/Socialuser', { useNewUrlParser: true, useUnifiedTopology: true });"
App.js file
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
let homePage = require('./models/home');
mongoose.connect('mongo://localhost:27017/Socialuser', { useNewUrlParser: true, useUnifiedTopology: true });
const app = express();
app.use(express.static(__dirname + '/public'));
app.get('/', (req, res) => {
res.render('landing.ejs');
});
app.get('/login', (req, res) => {
res.render('loginSignUp.ejs');
});
app.get('/home', (req, res) => {
console.log(homePage);
homePage.create({ name: 'wasim', image: 'https://www.w3schools.com/w3css/img_lights.jpg' }, (err, home) => {
if (err) {
console.log(err);
} else {
console.log('saved');
}
});
});
app.listen(3000, () => {
console.log('server started at port 3000');
});
here is my home.js file.it's the home schema file
const mongoose = require('mongoose');
let homePageSchema = new mongoose.Schema({
name: String,
image: String
// comments: [ String ]
});
module.exports = mongoose.model('Home', homePageSchema);
what is the actual problem i didn't getting what is going on. 'UnhandledPromiseRejectionWarning: MongoParseError: Invalid connection string' .....this problem is going
(node:22464) UnhandledPromiseRejectionWarning: MongoParseError: Invalid connection string
at parseConnectionString (C:\Users\wasim\Desktop\social\node_modules\mongodb\lib\core\uri_parser.js:547:21)
at connect (C:\Users\wasim\Desktop\social\node_modules\mongodb\lib\operations\connect.js:277:3)
at C:\Users\wasim\Desktop\social\node_modules\mongodb\lib\mongo_client.js:222:5
at maybePromise (C:\Users\wasim\Desktop\social\node_modules\mongodb\lib\utils.js:662:3)
at MongoClient.connect (C:\Users\wasim\Desktop\social\node_modules\mongodb\lib\mongo_client.js:218:10)
at C:\Users\wasim\Desktop\social\node_modules\mongoose\lib\connection.js:713:12
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (C:\Users\wasim\Desktop\social\node_modules\mongoose\lib\connection.js:710:19)
at Mongoose.connect (C:\Users\wasim\Desktop\social\node_modules\mongoose\lib\index.js:335:15)
at Object.<anonymous> (C:\Users\wasim\Desktop\social\app.js:6:10)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
(node:22464) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:22464) [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.