My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Mongoose query for documents that got likes on last 24 hours

Argjend's photo
Argjend
·Feb 18, 2020

I have this article schema:

 var article  = new mongoose.Schema({



        likes: [{
                    id: ObjectId,
                    by: {type: ObjectId, ref: 'User'},
                    created_at: {type: Date, default: Date.now}

         }],


}, {timestamps: {createdAt: 'created_at'}});

on which I store the likes that the story gets. As you can see the field likes stores users who liked the article and the time they liked the story.

Now I want to query all the articles that got likes in the last 24 hours. How is that possible to do in Mongoose?