These are chat archives for Automattic/mongoose

Aug 2016
Dávid Kőszeghy
Aug 09 2016 19:28
hey guys, anybody know how to solve RangeError: Maximum call stack size exceeded? I am trying to bulk save big number of documents, by first creating plain js objects which match schema model and then calling Model.collection.inser(arrayOfObjects, {}, callback) where even when array has 5 objects I get RangeError
Eric Grosse
Aug 09 2016 19:58
When you use a schema post hook, is there a way to compare the old document state to the new one?
In the docs it shows'save', function(doc) {
  console.log('%s has been saved', doc._id);
But that only gives you the updated doc state
I'm trying to setup cascade behavior where changing a user's userID updates all the userIDs for his associated blogs and posts
I've been using handlers such as the following
  put: function(req, res, Model, userId) {
    var Models = [Model.User, Model.Blog, Model.Post];

    // Only cascade for changes to the user's username
    if (req.body.username) {
      Promise.all(, index) {
        // If Model.User, update the username of just that user.
        // Else if Model.Blog or Model.Post, update the userId of all the blogs and posts pertaining to that user.
        if (index === 0) {
          return model.findOneAndUpdate({username: userId}, {username: req.body.username});
        else {
          return model.update({userId: userId}, {userId: req.body.username}, {multi: true});
      .then(function() {
      .catch(function(err) {
    else {
      routeHandler.put(req, res, Model.User, {username: userId});
But then I have to write a handler like this for every PUT request I make, which is why doing the cascade through the post hook would be so much more convenient (and less error prone)
Aug 09 2016 21:54
Hi guys, looking for some help, I can't return my value when Im doing a find query in my database... Here is my code
function getBankAmount(user) {
    ladderboardPlayer.findOne({name: user}).exec(function(err, doc) {
            console.log( //returns 10000
            return; //returns undefined
Cristyan Sepúlveda V
Aug 09 2016 22:00
Hello, anyone knows a good article about data modeling?
Daniel Meng
Aug 09 2016 22:34
@antoine2vey query looks okay to me. Have you checked it against the raw data? The other possibility is if Mongoose wasn't able to validate this scheme field for some reason