pedro.olimpio
pedro.olimpio

Reputation: 1498

Node.js - Why mongoose not saving data?

I've the following code:

const Box = mongoose.model("box", {
        _id: mongoose.Schema.ObjectId,
        mac: String
    });

    Box.findOne({ mac: "MACADDRESS" }, function (err, data) {

        data._doc.name = "box 2";

        data.save(function (err) {
            if (err) {
                console.log(err);
                return;
            }

        });

    });

I can't identify why the document is not saving. Anyone can help me?

Upvotes: 0

Views: 127

Answers (1)

krish
krish

Reputation: 537

Your model definition has mac in the attribute so it may go like this

Box.findOne({ mac: "MACADDRESS" }, function (err, data) {
    data.mac = "box 2";
    data.save(function (err) {
        if (err) {
            console.log(err);
            return;
        }
    });
});

Upvotes: 3

Related Questions