Mongoose save() not working/saving

If save() does not save the entity to mongodb database, probably there’s something wrong with the data itself like containing _id field

delete data._id; //clean up to ensure no _id field.
let user = new User(data);
user.save();

Also it is better to provide error handling so we can read what went wrong using the log.

let user = new User(data);
user.save(function (err) {
            if (err) {
                console.log(err);
            }
        });
Add to my src(1)

No account yet? Register

Install MongoDB server on Fedora command

sudo vi /etc/yum.repos.d/mongodb.repo

[Mongodb]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

sudo dnf update
sudo dnf install mongodb-org
sudo systemctl enable mongod.service
sudo systemctl start mongod.service
mongod --version
mongo

> use test;
switched to db test
> db.test.save({'hello':'world'})
WriteResult({ "nInserted" : 1 })
> db.test.find()
{ "_id" : ObjectId("5f82b166af5d9be8c5bd0449"), "hello" : "world" }
> 
Add to my src(0)

No account yet? Register

Install Mongodb server on Debian / Ubuntu

sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo systemctl daemon-reload
sudo systemctl start mongod
sudo systemctl status mongod
sudo systemctl enable mongod

sudo systemctl stop mongod
sudo systemctl restart mongod
Add to my src(0)

No account yet? Register