These are chat archives for Automattic/mongoose

21st
Apr 2016
Christoph Werner
@codepunkt
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
@codepunkt
Apr 21 2016 13:35
Okay, i used a pre validation hook to do that. Seems to work fine.
Was that a good idea? :)
LeonineKing1199
@LeonineKing1199
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
@euginio
Apr 21 2016 19:37
Thankyou @vladotesanovic @Nepoxx.
I think I will try with this
https://github.com/angular-fullstack/generator-angular-fullstack
or this
http://meanjs.org/generator.html
Pier-Luc Gagnon
@Nepoxx
Apr 21 2016 19:37
let us know how it works out for you
This message was deleted
Vlado Tesanovic
@vladotesanovic
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
@siboulet
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()?