'failed to post data at local mongodb from node.js
This code is of the connect to the mongodb i can see in console that successfully connect to mongodb i cant create a new user by sending data in the request boby.
const mongoose = require('mongoose');
const mongoURI = "mongodb://localhost27017/?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false"
const connectToMongo = () => {
mongoose.connect(mongoURI, () => {
console.log("Connected to Mongo Successfully");
})
}
module.exports = connectToMongo;
This code is for authentication end point
const express =require('express');
const User = require('../models/User');
const router = express.Router();
const user = require('../models/User');
router.post('/', (req,res)=>{
res.send(req.body);
const user = User(req.body);
console.log(req.body);
user.save;
})
module.exports = router;
Solution 1:[1]
Its just problem with the connection string and a typo.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shivam Rana |
