These are chat archives for Automattic/mongoose

13th
Jan 2017
Jackson Delahunt
@sabrehagen
Jan 13 2017 01:40
generally, how many milliseconds does a replica set election take to reach consensus and the new master handling writes? assuming ~1-2ms network latency
Erinç Fırtına
@EricMcRay
Jan 13 2017 07:57
@sabrehagen it depends on your replica set config
Michael Lynn
@mrlynn
Jan 13 2017 08:00
New versions of MongoDB (3.2+) leverage the RAFT Protocol... this resulted in dramatically improved failover timings... Pre- 3.2 could have been in increments of 30 seconds... whereas 3.2 could be as low as 2 seconds - depending on your specific configuration.
Alex Munoz
@AlexMunoz
Jan 13 2017 13:40
how finish mongoose connection after insert some elements?
Joseph Chambers
@imcodingideas
Jan 13 2017 22:31

Hello, I have a question. I have here: https://gist.github.com/imcodingideas/0e5f19b0a291909e7744191857a212d8 that a gift belongs to a user. However, Im trying to save a user can have many gifts. Here is my user model: https://gist.github.com/imcodingideas/8ae7819c134279e6587c5677aee141c1

When I create a new gift:

// Create a Gift
router.post(
  '/',
  middleware.isLoggedIn,
  (req, res, next) => {

    // get data from form and add to gift array.
    let user = req.body.user,
      giftNumber = req.body.giftNumber,
      date = req.body.date,
      giftDescription = req.body.giftDescription,
      giftAmount = req.body.giftAmount,
      giftCode = req.body.giftCode,
      redeemCode = req.body.redeemCode,
      passCode = req.body.passCode,
      senderFirstName = req.body.senderFirstName,
      senderLastName = req.body.senderLastName,
      giftMessage = req.body.giftMessage,
      newGift = {
        user: user,
        giftNumber: giftNumber,
        date: date,
        giftDescription: giftDescription,
        giftAmount: giftAmount,
        giftCode: giftCode,
        redeemCode: redeemCode,
        passCode: passCode,
        senderFirstName: senderFirstName,
        senderLastName: senderLastName,
        giftMessage: giftMessage
      };

    Gift
      .create(newGift, (err, newlyCreated) => {
        if (err) {
          req.flash('error', err.message);
        }
        res.redirect('/admin/created-gift');
      });

  });

what I see in the database for the user when I create a new gift: "gifts" : [], it's empty. What am I doing wrong?