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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -