These are chat archives for Automattic/mongoose

9th
Sep 2015
Benjamin Montgomery
@bmonty
Sep 09 2015 00:43
@jrthib calling done() helps, but isn't the only answer. I've found that you shouldn't make any assumptions about the order that mocha executes your tests. The only time that's been an issue for me is with testing code that uses mongoose.
@vkarpov15 can't use mongoose.createConnection() in my application. Also, my code only creates one connection but in testing I have the connection being connected and disconnected between each test.
End solution for me was to add code that checks for open connections and doesn't call mongoose.connect() if mongoose.connection.readyState === 1.
Valeri Karpov
@vkarpov15
Sep 09 2015 13:06
The other option is just call mongoose.connect() at the top of your test file before any describe() calls
however, that's why using mongoose.connect() is typically not the right choice. It's convenient for quick-and-dirty hacks, but it suffers from the same limitations as all global state
IMO the fundamental law of software engineering is that global state is hard to test
Richard Brookfield
@dvideby0
Sep 09 2015 14:15

Im having some issues with REGEX performance. When I use robomongo the response times are about 0.039 seconds but with mongoose they seem to take about 30 seconds..
Here is my query

twitterFriends.find({
      $and: [
        {$or: screen_names},
        {
          $or: [
            {
              friend_screen_name: {
                $regex: message.body.payload.query_params.search_value,
                $options: 'ig'
              }
            },
            {
              friend_name: {
                $regex: message.body.payload.query_params.search_value,
                $options: 'ig'
              }
            }
          ]
        }
      ]
    }, {_id: 0, friend_screen_name: 1, friend_name: 1, friend_icon: 1})
        .limit(5)
        .exec(function(err, records) {

Is there something glaring I am doing wrong?

I am using "mongoose": "^4.1.0”
Valeri Karpov
@vkarpov15
Sep 09 2015 16:08
@albertorestifo do you have any weird characters in your username/password - '@', ':', etc?
@dvideby0 try enabling mongoose debug mode, require('mongoose').set('debug', true); and see what the query is, and then try executing it in the shell
hard to imagine anything in mongoose itself running for 30 seconds - I'd guess this is indicative of an index miss. Roughly how many docs are in this collection?
Richard Brookfield
@dvideby0
Sep 09 2015 16:21
There are about 5million
its a pretty small collection.
We tried to isolate the request and found that this may just be a symptom of a issue that we have not uncovered.
Isolated, the response times were as expected and so we are digging deeper. I apologize for having assumed it was this request.
and thank you for the help!