I have a node/express app using mongo.
I have a collection called "paymentMethods", where I store documents that contain the following:
{
owner_id,
name_on_card,
card_number_last_4,
isActive
}
An owner can have multiple cards in this collection.
When I add a new card, I make the "isActive" true, like so:
router.route('/')
.post(function( req, res ){
PaymentMethod.findAndUpdate({owner_id:req.body.ownerId})
var paymentMethod = new PaymentMethod();
paymentMethod.owner_id = req.body.ownerId;
paymentMethod.card_number = req.body.cardNumber;
paymentMethod.name_on_card = req.body.nameOnCard;
paymentMethod.exp_date = req.body.expDate;
paymentMethod.cvv = req.body.cvv;
paymentMethod.zipcode = req.body.zipCode;
paymentMethod.active = true;
console.log('Payment information passed: ', paymentMethod);
paymentMethod.save(function(err, paymentMethod){
if(err)
res.send(err);
res.json(paymentMethod);
})
});
What I'm trying to figure out is how I can, in the same call, update all the other matching records and set their "isActive" fields to null or false.
Thanks in advance to the gurus!!