These are chat archives for Automattic/mongoose

30th
Apr 2015
Valeri Karpov
@vkarpov15
Apr 30 2015 00:38
@Jks15063 if save is broken, its not in any way that we've tested so far. Can you open up an issue and provide some more context, preferably a standalone script that reproduces your issue?
@Alamphear85 i don't quite understand, can you show some code?
Valeri Karpov
@vkarpov15
Apr 30 2015 01:30
@Jk
Jake Sellers
@Jks15063
Apr 30 2015 15:52
vkarpov15: so, the bug shows up only after the upgrade, but it is not the upgrade, at least not purely
@vkarpov15
I created a new file in the project dir, imported mongoose, connected to db, ran findOne, doc.set( ... ), and doc.save(callback) and the doc is saved and callback executed just fine
double checked that the real function I'm looking at has the same format and is in fact receiving a mongoose doc object
it is
the callback is just not firing
Valeri Karpov
@vkarpov15
Apr 30 2015 16:44
That's really strange. I figured it's something non-trivial because .save() is definitely something we test quite heavily :) open up an issue if you can find a script that reproduces the issue.
Something that may be helpful: enable debug mode require('mongoose').set('debug', true); and it will print out every database operation. Will help you bisect and see if the insert / update is actually getting sent or not
Jake Sellers
@Jks15063
Apr 30 2015 16:45
@vkarpov15 I'll try the debug, I cannot reproduce the problem lol
Jake Sellers
@Jks15063
Apr 30 2015 16:52
ok so it looks like the save isn't even firing
Jake Sellers
@Jks15063
Apr 30 2015 17:01
@vkarpov15 issue reproduced
function findADoc() {
    return newTest.findOne({}).exec();
}

findADoc()
.then(function(doc) {
    console.log(err, doc);
    doc.set('foo', 'wut');
    doc.save(function(error) {
        console.log('->', error);
    });
});
.then is hit, doc is logged, but save is never fired
something to do with being passed through a promise chain
idk if its a bug in mongoose or I'm just being dumb
tried various combinations of wrapping it with Q
Jake Sellers
@Jks15063
Apr 30 2015 17:07
return Q(newTest.findOne({}).exec());
Q.when(findADoc)...
I always get the doc, but save does not fire
Joseph Thibeault
@jrthib
Apr 30 2015 18:24
if i use virtual setters to set required schema fields, will it return a validation error or will the required field value be set prior to being run through validation