These are chat archives for Automattic/mongoose

Apr 2016
Christoph Werner
Apr 21 2016 11:34
is there any way to create a required field based on the values of two other fields?
creating a required field based on the value of another field is easily done using a setter
token: {
  type:  String,
  required: true
userId: {
  type: Schema.Types.ObjectId,
  required: true,
  set (userId) {
    this.token = jwt.sign({ userId })
    return userId
but what if i want to create the token not only based on the userId, but also a tenantId field that is basically equivalent to userId?
Christoph Werner
Apr 21 2016 13:35
Okay, i used a pre validation hook to do that. Seems to work fine.
Was that a good idea? :)
Apr 21 2016 15:09
This may sound stupid but I'm checking the Mongoose API, would a "plugin" work for your needs?
Eugenio Arosteguy
Apr 21 2016 19:37
Thankyou @vladotesanovic @Nepoxx.
I think I will try with this
or this
Pier-Luc Gagnon
Apr 21 2016 19:37
let us know how it works out for you
This message was deleted
Vlado Tesanovic
Apr 21 2016 19:39
I have one question, question is between MongoDB itself and Mongoose. Are anyone of you handle large data sets in MongoDB? I am talking about million of documents in collection.
Simon Boulet
Apr 21 2016 20:30
Hi, I'm trying to use .id() on populate()'d array. Is there a particular reason why id() isn't available for populated arrays? Is the only replacement for id() is cycle manually through the array and match _id or using Array.find()?