These are chat archives for LearnBoost/mongoose

Feb 2015
Cristian Wilgenhoff
Feb 11 2015 21:11
Hi guys, I'll appreciate help on this one:
I have a collection like follows in mongo:
[{ title: 'Title', desc:'desk', order:1},{ title: 'Title', desc:'desk', order:2},{ title: 'Title', desc:'desk', order:3}]
I want to change the order of an item (based on 'order' property)
This means I need to use a multi-edit something like this
model.update({order: > 1},{$set:{inc:1}},{multi:true})
But, this doesn't work for extreme case, because holes can be created. For example when changing 3 with 2, a hole is created
Does some had to do this with a project and come back with a solution to implement this in one just line of an update?
Valeri Karpov
Feb 11 2015 22:43
Hmm I'm not sure I understand @cwilgenhoff - do you mean a single update that changes order: 2 with order:3 and vice versa?