These are chat archives for Automattic/mongoose

29th
Apr 2016
pdiogo
@PedroMD
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
@vladotesanovic
Apr 29 2016 08:58
@PedroMD excellent :+1:
pdiogo
@PedroMD
Apr 29 2016 08:59
thanks a lot ;)
one more question
result. unshipedItems.push({'refs.item': doc.item, 'refs.counter': 1}); result.save();
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
pdiogo
@PedroMD
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:
$pull
$pullAll
$pop
$set of an entire array
$push
$pushAll
$addToSet

from: http://aaronheckmann.tumblr.com/post/48943525537/mongoose-v3-part-1-versioning

its the array.push, not the save() itself
Vlado Tesanovic
@vladotesanovic
Apr 29 2016 17:46
@PedroMD i see your messages now, you solved it.
Valeri Karpov
@vkarpov15
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
LeonineKing1199
@LeonineKing1199
Apr 29 2016 22:40
I sharded once but that was after a night of drinking and Buffalo Wild Wings