These are chat archives for Automattic/mongoose

13th
Apr 2016
追随
@zyf0330
Apr 13 2016 01:05
Hello, anybody here?
Pier-Luc Gagnon
@Nepoxx
Apr 13 2016 13:07
Don't wait for one of us, just ask away :)
Vlado Tesanovic
@vladotesanovic
Apr 13 2016 13:38
@Nepoxx i see that you forked mockgoose, probably you tested something... What experience do you have with it? Are you using that in your real project?
I am in process of modeling one big application, and unit tests should be in place, of course. I am dependent on mongoose, and i have created much custom ( static ) mongoose methods which i want to test.
Pier-Luc Gagnon
@Nepoxx
Apr 13 2016 13:39
I am using mockgoose yes
Vlado Tesanovic
@vladotesanovic
Apr 13 2016 13:39
what you think about it, overall?
Pier-Luc Gagnon
@Nepoxx
Apr 13 2016 13:40
In all honesty I'm not doing anything advanced, I just use it during my tests to make sure my DB is not used
Works very well for my purposes
Vlado Tesanovic
@vladotesanovic
Apr 13 2016 13:40
ok, in your project you are probably dependent on pre inserted data?
you are doing that in before methods?
Pier-Luc Gagnon
@Nepoxx
Apr 13 2016 13:41
I do some integrations tests as well, and it's useful to check that, for instance, if you PUT some data, you can retrieve the same data with a GET. Obviously it's not the same thing as a "real, live" integration test, but it works for me
That's right, I have a "globalTestHooks" with some prep in my before
Vlado Tesanovic
@vladotesanovic
Apr 13 2016 13:41
yea but that anyway should work
yea that is approach i am taking
Diego Aguilar Aguilar
@diegoaguilar
Apr 13 2016 15:17
I have a really strange issue with Mongoose, I got following code:
module.exports.search = (req, res) => {
  let search = req.query;
  if ('name' in search) {
    search = { name: { $regex: search.name, $options: 'i' } };
  }
  Product.find(search)
    .execAsync(results => {
      return res.json({
        results: results,
        query: req.query
      });
    })
    .catch(err => {
      return res.status(500).json({errors: err});
    });
};
API works
blob
but its returning no results while cosulting at mongo cli throws results
blob
it's same DB, but can't get why it wouldn't work via mongoose
LeonineKing1199
@LeonineKing1199
Apr 13 2016 15:21
Let me see if I understand, your API call works (you're getting a 200 back) but the Mongoose code isn't returning anything while a CLI-based approach does give you something back?
That would be strange... Is mongoose connecting to the right DB?
Diego Aguilar Aguilar
@diegoaguilar
Apr 13 2016 15:21
yep, it is
pretty sure
LeonineKing1199
@LeonineKing1199
Apr 13 2016 15:22
Hmm... Can you get anything back from Mongoose? What if you tried a super simple thing like Query.find({})?
Diego Aguilar Aguilar
@diegoaguilar
Apr 13 2016 15:23
kk, let me try ...
duuh my bad
I have such a syntax err
I have execAsync(results=> {})
it should be ... execAsync().then(...)
LeonineKing1199
@LeonineKing1199
Apr 13 2016 15:26
Ha ha ha ha. You know what's funny, I've never seen the execAsync function...
Diego Aguilar Aguilar
@diegoaguilar
Apr 13 2016 15:26
lol
sorry!
LeonineKing1199
@LeonineKing1199
Apr 13 2016 15:26
Normally my Mongoose stuff looks like this:
Query
  .find({})
  .then(results => { /* ... */ })
Diego Aguilar Aguilar
@diegoaguilar
Apr 13 2016 15:27
yep, how are promises working in last mongoose version
Im still hacking it with bluebird
LeonineKing1199
@LeonineKing1199
Apr 13 2016 15:27

Oh, I see XD

We use the ES6 Promises.

mongoose.Promise = global.Promise

Diego Aguilar Aguilar
@diegoaguilar
Apr 13 2016 15:28
can I do .then().catch()
?
LeonineKing1199
@LeonineKing1199
Apr 13 2016 15:28
Yup :)