node.js - Sorting using created at and updated at in mongodb -


why need created_at or updated_at sorting since objectid contain timestamp.

we can do

products.find({"p":p}).sort({'_id': 1}).exec(callback); 

or

products.find({"user_id":user_id}).sort({'_id': -1}).exec(callback); 

correct me if i'm wrong.

assuming created_at date when document has been created, , updated_at date of latest document update:

if don't use either of these fields in application, there chances don't need them.

there few usecases document's id not enough:

  • filter or group created_at
  • filter, group, or sort update_at

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -