These are chat archives for Automattic/mongoose

11th
Jun 2018
julian libor
@Linux249
Jun 11 2018 13:59

Hey guys,

i'm trying to build a setter function that save my old values if they change. I came up with this idea:

function setter(v, s) {
            console.log(this)
            return v
        }
        const string = {
            v: {
                type: String,
                default: null
                set: setter,
            },
            o: [],
        }

        const ExampleSchema = new Schema({
            foo: string,
            bar: string,
        });

if i look a "this" inside the setter function i don't the the stuff behind 'bar' if the s.path is 'bar' but i can see 'foo' as aspected (cause of the default value) and the other way around the same. I have like 20 key and is always the same problem. Does anyone have some idea's?

julian libor
@Linux249
Jun 11 2018 14:58
ok, i suppose thats this may be an issue with may way to update docs (Object.Assign(doc, req.body)
what is a good way to update my docs if I have to trigger the save middleware and get the new data from the req.body (epress/body-parser)? i cannot change every key individuelly