0

I have a problem with a query on mongodb. First of all, I have this object on my mongoose schema, like this

obj_proof: {
        field1_proof: String,
        field2_proof: String 
}

I would like to make a query on mongo in which a part of a field name changes automatically(really it is passed as parameter of a function) This is an example:

var attr = 'obj_proof.'+field; //field is passed by the some function in which                there is this code
    ProofSchema.update({ 'Id': Id }, { attr : value }, function(err, result) {  //Id is another parameter that is passed by the same function, like field and value
});

But it doesn't work. The problem is that I don't want to duplicate this function , because the obj_proof is always the same. On the other hand, field changes.

1 Answer 1

2

Try This

var attr = 'obj_proof.' + field; //field is passed by the some function in which                there is this code

var key_attr = {};
key_attr[attr] = value; // the value


ProofSchema.update({'Id': Id}, key_attr, function(err, result) {  //Id is another parameter that is passed by the same function, like field and value
});

Thanks

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.