These are chat archives for Automattic/mongoose

13th
Oct 2017
Paul "Joey" Clark
@joeytwiddle
Oct 13 2017 06:37
@pantchox I would query first to get the IDs. Then remove the IDs I just queried.
I would feel cleaner removing the Cs first, then the Bs, then the A.
Vlado Tesanovic
@vladotesanovic
Oct 13 2017 09:13
@jemliF i can't find your original message to see your code
YasaaMoin
@Yasaa
Oct 13 2017 09:40
Anyone who has a backend project in mind,but needs a front end guy to complete the project,then pm me,I'll gladly take it.
Peter Bailey
@pea
Oct 13 2017 12:04
mongoose.Promise = global.Promise;
mongoose
  .createConnection(process.env.MONGODB_CONNECTION_STRING, {
    useMongoClient: true
  })
  .then(() => {
    const user = new User();
    user.findOneAndUpdate(
      {stravaId: payload.athlete.id},
      {
        stravaId: payload.athlete.id,
        stravaCode: req.query.code,
        email: payload.athlete.email
      },
      {upsert: true},
      err => {
        console.log(err);
      }
    );
  })
  .catch(err => {
    console.log(err);
  });
Anyone had "TypeError: user.findOneAndUpdate is not a function" before? Can’t see any problems with my code.
Nick Rameau
@R4meau
Oct 13 2017 15:00
@pea Just use User.findOneAndUpdate, unless you really need to use the object user later, I don't think it will work your way.
Supposing User is your model.
Peter Bailey
@pea
Oct 13 2017 15:18
Mmm well that error has disappeared. No document but I’m guessing that’s another problem. Thanks
Peter Bailey
@pea
Oct 13 2017 20:00
Is the documentation just out of date? The docs are telling me one thing, the error log is telling me another