These are chat archives for Automattic/mongoose

Aug 2015
Aug 20 2015 14:52
Mikael Pettersson
Aug 20 2015 15:04
I’m trying to update a user in a collection, and I have all passports stored in an embed… Question is .. how do I use findOneByIdAndUpdate, with out it removing the hashedPassword, salt etc (since they aren’t passed to the user, they aren’t included in the data to be updated)?
But I still want the user to be able to add or remove entire passports.. those are included in the updated data
Aug 20 2015 16:57
Auth.findOne({nick: 'noname'}, function(err,obj) { console.log(obj); });
obj._doc is has all fields from found Mongo document and this fields are read-only?
This message was deleted
Aug 20 2015 17:06
If I need to change this document I should write direct to obj
All fields from _obj are not available in obj
Aug 20 2015 17:39
So i found a tutorial on how to encrypt passwords with mongoose - basically it uses the schema.pre('save', fn) to import bcrypt and encrypt it.
Question: why not do it on the node file and just pass the encrypted string?
Aug 20 2015 20:58
I don't know if I'm doing the wrong approach to this, but I have an 'event' that can have around 40 documents referenced (populate). They all come in at the same time. I want to ensure that all those documents are saved correctly before saving the parent 'event'. Is there a way to skip validation on saving so that I can do validate() on all of them before trying to save?
Or does mongoose know that they already are valid when I try to save?
Those documents aren't large and 40 is the maximum amount, but then I'd have to deal with nested arrays (3 levels), and those documents will be updated individually far more often than the 'event' document
in regards to using subdocs instead
Nick Stefan
Aug 20 2015 22:30
Is it normal for a query.lean().exec() to give such an odd _id value?
  { name: 'Mustang',
    updated_at: Thu Aug 20 2015 15:26:42 GMT-0700 (PDT),
    _id: { _bsontype: 'ObjectID', id: 'UÖT"¯6P(ì\\„' },
    __v: 0 }
how can I get a string rep of the _id ?
Nick Stefan
Aug 20 2015 22:45
so i see in the docs that id is a virtual getter on a "doc". Is there a way to have .lean() cast _id or id property to simple string?