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
Post a Comment