Filter by timestamp in Object ID in MongoDB
Use something like this to filter based on timestamp embedded within MongoDB Object id:
db.yourcoll.find({
"$expr":{
"$and":[
{$gte:[{"$toDate":"$_id"}, "$c9_thismonth-2m"]},
{someOtherField: 'someval'}
]
}
},{timestamp:{$toDate:"$_id"}}})
)
Please sign in to leave a comment.
0 comments