javascript - Store order value in collection in Meteor -
i want order collection.
i need store field order
storing incrementing numerical value.
so docs have values 1,2,...,n.
the problem different docs belong different projects (by projectid
) cannot have "normal auto-incrementing" field.
how done? guess use like
var lastdoc = mycollection.findone({ projectid: projectid }, { sort: { order: -1 } }); var nextorder = lastdoc ? lastdoc.order + 1 : 1;
every time insert documents. correct? if delete 1 of docs between other docs?
Comments
Post a Comment