These are chat archives for Automattic/mongoose

12th
Sep 2016
Jake Lees
@brocococonut
Sep 12 2016 06:16
I was wondering, is it at all possible to put a populate query inside of a json object (the options section of the query). An example of a before and after I'd be looking of is:
Comments.findOne({_id: idvar})
.populate(populateQuery)
.exec(...)
to:
Comments.findOne({_id: idvar}, {populate: {populateoptionshere}, function(...)...)
Emmanuel
@unuigbee
Sep 12 2016 12:58
Does anyone know how to empty and update an array of refs, for some reason I keep getting the error "Cannot read property '$isMongooseDocumentArray' of undefined";
const query = { _id: id }; const update = { $set: { commandSequenceTitle, commandSequenceDescription, commands }, }; const options = { new: true }; return this.UserCommandModel.findOneAndUpdate(query, update, options) .exec() .then(({ _id, commandSequenceTitle, commandSequenceDescription, commands, createdAt, updatedAt }) => { }) .catch((err) => { console.log(err); });
Emmanuel
@unuigbee
Sep 12 2016 13:06
Basically the commands property is an array of refs referencing another document and I'm wondering how I can set a new set of refs for a particular document.
Emmanuel
@unuigbee
Sep 12 2016 13:25
LeonineKing1199
@LeonineKing1199
Sep 12 2016 15:19
Hey, has anyone ever had any save issues?
Right now, I'm updating an array of documents but for some reason, the numAffected paramater in the callback is 0 even though err is null
LeonineKing1199
@LeonineKing1199
Sep 12 2016 15:51
Okay, I wound up getting what I needed to work to work by swapping a save with an update call. I've no idea why the save was failing. No errors yet numAffected was 0 in the callback.
Peter B Smith
@peterbsmith2
Sep 12 2016 15:52
I've had that same issue
I can't remember what i did to fix
there was a way to do it with save, though i believe a config option had to be passed so that it would give accurate output
LeonineKing1199
@LeonineKing1199
Sep 12 2016 15:53
Weird.
I see no good reason for the save to fail either. It's a relatively simple schema, maybe a few required props but that's about it.
I had all these asserts around the required props and everything.
Oh well.
Emmanuel
@unuigbee
Sep 12 2016 16:33
Fixed my issue I was calling the wrong schema model :(
nacq
@nacq
Sep 12 2016 16:55
Hi guys, whats the best way to handle WriteError code: 11000 (native mongodb error)?
Jason Kruse
@mnisjk_twitter
Sep 12 2016 18:55
Hi room, does anyone know (or can point me somewhere to look) regarding updating a model property's schemaType (specifically from a String to an Array) and how it may or may not affect existing documents?
I did a small experiment and it would appear the existing documents' property are preserved. The only difference seems to be when queried, that property will be an array (of size one) containing the original String property. But a little apprehensive to make this change in production without further confirmation