Tagnosql

MongoDB – Incremental IDs

M

I’ve been reading a lot recently on MongoDB and the use of incrementing an ID This article offers an in depth look: Taking this a little further, and from reading the findAndModify documentation I put together the following: db.sequence.findAndModify({ query: {"_id": "customer"}, update : {$inc : {"seq":1}}, upsert:true, new:true}) Here is what this command does: Finds (or creates) the “sequence”...