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' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -