Hi,
I am new to mongoDB and i have installed a 6.0 community server on my ubuntu server.
I have followed the tutorials on the site, i have enabled the access from other server , i have create a super user , a collection and an admin user for that collection with roles of adminDB and readWrite.
my problem is that when i am trying to sent a POST request i am getting an error 13 Unuthorised.
i am using mongoose and nodejs to connect (following code with changed loggin data)
mongoose.connect(mongodb://username:password@ip:port/dbname,{
useNewUrlParser:true,
useUnifiedTopology:true,
});
and the following code to POST from node
app.use(express.json());
app.post(`${api}/products`,(req,res)=>{
const product = new Product({
name: req.body.name,
image: req.body.image,
countInStock: req.body.countInStock
});
product.save()
.then((createdProduct)=>{
res.status(201).json(createdProduct);
})
.catch((err)=>{
res.status(500).json({
error: err,
success:false
});
});
});
If i use MongoDBCompass I can add data
any idea how on where is the error ?