1

I'm trying to use .native() to update multiple records. Here's my code:

// Controller

Pet.native(function(err, collection) {

    // For demo purposes only. Correct owner is returned previously from Owner.findOne()
    var owner = {
        id: '55b6989ca03b83e846198b18',
        foo: 'Foo',
        bar: 'Bar'
    };

    collection.update({
        _id: {
            "$in": ['55b69860a03b83e846198b13', '55b69860a03b83e846198b10'] // get all pets in array
        }
    }, {
        "$push": {
            owners: owner // append owner to each selected pets
        }
    }, {
        multi: true
    }, function(err, result) {
        console.log("Owner ADDED");
    });
});

// User.js Model

module.exports = {
    schema: true,

    attributes: {
        petsOwned: {
            collection: 'pet',
            via: 'owners'
        },
    }
}


// Pet.js Model

module.exports = {
    schema: true,

    attributes: {
        owners: {
            collection: 'user',
            via: 'petsOwned'
        },
    }
}

After adding, if I populate the owners in Pet it's always empty. Pet.find().populate('owners').exec(console.log)

coder9
  • 1,571
  • 1
  • 27
  • 52

0 Answers0