D
D
DarkNetFox2020-05-17 12:28:26
JavaScript
DarkNetFox, 2020-05-17 12:28:26

Mongoose doesn't save array changes, what should I do?

I have a database on mongoose

Scheme
const user = new mongo.Schema({
    profile: {
        id: Number,
        nick: String,
        gold: Number,
        health: Number,
        health_max: Number,
        status: {
            id: Number,
            name: String
        }
    },
    documents: {
        passport: {
            name: String,
            availability: Number
        },
        pass: {
            quantity: Number,
            _type: Number
        }
    },
    training: Boolean,
    locate: Number,
    stage: Number,
    food_warehouse: Array
});

I need to change the content of food_warehouse
example
было:
food_warehouse: [{name: "яблоко", "id": 1}]
нужно чтоб стало:
food_warehouse: [{name: "яблоко", "id": 0}]

The code:
_user.updateOne({"food_warehouse.id": _user.food_warehouse[i].id}, {
            $set: {
                "food_warehouse.$.id": 123
            }
        },
        {strict: false})


values ​​are not updated
how can i update?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question