Instead of creating an instance of a model, and saving it on a different step like this:
// Create an instance of model SomeModel
var awesome_instance = new SomeModel({ name: 'awesome' });
// Save the new model instance, passing a callback
awesome_instance.save(function (err) {
if (err) return handleError(err);
// saved!
});
I want to to do it all in a single step like this:
SomeModel.create({ name: 'also_awesome' }, function (err, awesome_instance) {
if (err) return handleError(err);
// saved!
});
The thing is that if I use the second case, I don’t know what would be a proper way to access the awesome_instance outside the callback, the keep working with it. I could assign it to global variable, but I just think there must be a “better” way.