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

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -