These are chat archives for Automattic/mongoose

7th
Dec 2015
Christopher Shelley
@basiclaser
Dec 07 2015 09:03
@vkarpov15 thanks a lot, thats really helpful!
Luke Childs
@lukechilds
Dec 07 2015 14:53
@vkarpov15 That's what I'm doing in my last message. When I was asking about the id I think I was thinking about it in the wrong way
Diego Aguilar Aguilar
@diegoaguilar
Dec 07 2015 17:10
Hello, where can I see the code to convert object id bytes to a string
I only need that instead of importing whole mongoose
Yordis Prieto
@yordis
Dec 07 2015 17:28
Is this the correct way to aggregate dates?
{
  '$match':{
    '$and': [{
      createdAt: {
        '$gte': new Date('Fri Dec 12 2014 17:06:36 GMT+0000 (UTC)'),
        '$lte': new Date('Sat Dec 12 2015 17:06:36 GMT+0000 (UTC)')
      }
    }]
  }
}
David Richardson
@daverich204
Dec 07 2015 22:44

I'm also having an issue with querying on Dates. No matter what I try to use I always get back 0 results: items = [];

My schema is defined as:

var IndexSchema = new Schema({
    symbol: {
        type: String
    },
    price: {
        type: Number
    },
    timestamp: {
        type: Date,
        default: Date.now
    }
});

I set a lower bound with something like this:

    var minDate = new Date();
    minDate.setDate(minDate.getDate() - 26);

and then try and run my query with:

    Indexes
    .find({'symbol':indexSymbol, 'timestamp': {'$lt': new Date() } })
    .sort({'timestamp': 1})
    .exec(function (err, items) {
         // handle results here.
    });

Yet I get no results back.

Changing the find conditions to something like:

    .find({'symbol':indexSymbol, 'price': { '$lte': 500 } })
   ...

works, it's only queries on this timestamp 'datae' object that cause no results to be returned.

Christopher Shelley
@basiclaser
Dec 07 2015 23:11
how do i specify which index to use when querying the DB? i have one ‘content index’(from title and content attributes) for text search queries typed into an input field, and another ‘tags index’ (from tag array attributes) to check for one or more predefined tags in a dropdown list. I can already query the ‘content index’ with a search field, how can i specify the tags index to start that feature?
Theo Sherry
@theosherry
Dec 07 2015 23:16
Hey, how do you all test methods/virtuals/hooks on your models that have dependencies? I'd like to be able to mock out require calls when testing a virtual property (that has external dependecies) on a model, but I'm running into problems with mongoose not able to compile models more than once.