These are chat archives for Automattic/mongoose

Dec 2015
James Lee
Dec 14 2015 03:03
@vkarpov15 will you take a look at ,
I'm receiving an error, maximum call stack size.
I'm not doing any loop and it looks straight forward. I'm not sure where to look to debug this. All the Google searches talk about loops etc...
The error does not occur if I save without add to set being called
James Lee
Dec 14 2015 04:43
@vkarpov15 figured it out. the map function on the cheerio object returned additional fields other than the elements i was looking for.
James Lee
Dec 14 2015 06:45
@vkarpov15 i'm seeing that the unique index for my subdocument is not working as expected. Google seems like it is telling me, unique indexes on a sub-doc array is not possible. Is this true? What is your recommendation on how I can go about doing this? Just create another collection? Here's the schema I'm working with.
unique index on my Path sub doc is the one in question
Valeri Karpov
Dec 14 2015 15:36
@uptownhr unique index on sub-doc array makes that value globally unique. If you want it to be unique within an array, you can either use addToSet or just check before saving your document and make sure to not use .push()
Dec 14 2015 15:59
Hi there
I am working in a project someone else wrote, and it's using mongoose.
he is using schemas and models, something such as:
var schema = mongoose.Schema({
    id: String,
    name: String,
    address: String,
    city: String,
    zip: String,
    country: String,
var Office = mongoose.model("Office", schema);
however when he creates instances (using new Office()) he accesses the properties as if they were native JS properties, e.g.
                office = new Office();
       = 'NY';
but I don't see in the mongoose docs that this is correct syntax.
is this allowed?
Luis Miguel Díaz Abril
Dec 14 2015 16:02
@ir-fuel You can do this, but then you could intefeer with Mongoose sugar, I would use get/set only
Dec 14 2015 16:02
well funny thing is
I encountered a WEIRD issue because of this
if(office.location !== null)
    console.log('Location exists ' + office.location);
this actually prints Location exists null
James Gardner
Dec 14 2015 16:35
Hi, need some guidance on best practices. I want to keep a separate collection of 'events' every time certain fields are changed/updated. My question is, where's the best place to do this? I've got a separate schema defined for the 'events'.
I can do it all within the route handler but it's not very DRY
So when field 'status' changes in Model A, Model B or C then add a new record to the events collection.
Dec 14 2015 16:39
@james-gardner I’d do it with middleware in express. Not sure if that is the best way, but it would keep things DRY
James Lee
Dec 14 2015 19:03
@vkarpov15 thanks