These are chat archives for Automattic/mongoose

Apr 2016
Apr 29 2016 08:58
ey @vladotesanovic! just got back on this issue and it is now solved. I just simply changed the sub-document a little bit var unshipedItemsSchema = new mongoose.Schema({ refs: { item: {type: Schema.Types.ObjectId, ref: 'Item', default: null}, counter : {type: Number, default: null} } }); this way I can keep track of the amount of unshipped items also indexed by each item
and the query was ok - I just needed to first determine if it had any value, before increment it
Vlado Tesanovic
Apr 29 2016 08:58
@PedroMD excellent :+1:
Apr 29 2016 08:59
thanks a lot ;)
one more question
result. unshipedItems.push({'refs.item': doc.item, 'refs.counter': 1});;
always yields a new version on my Model (the _v property) - is it because of the save() ?
because when I do update(), it does not inc _v
Apr 29 2016 09:07
looks lit it is related to the array position
doesn't seem to be harmful..

In version 3, documents now have an increment() method which manually forces incrementation of the document version. This is also used internally whenever an operation on an array potentially alters array element position. These operations are:
$set of an entire array


its the array.push, not the save() itself
Vlado Tesanovic
Apr 29 2016 17:46
@PedroMD i see your messages now, you solved it.
Valeri Karpov
Apr 29 2016 22:39
@PedroMD correct. That blog post explains versioning and the reasoning for it quite well. Long story short, if you never delete array elements in-place, you'll never notice it
@keverw scatter-gather query, the driver will hit all the shards
Apr 29 2016 22:40
I sharded once but that was after a night of drinking and Buffalo Wild Wings