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

Help needed with MongoDB!

Deactivated User's photo
Deactivated User
·Apr 27, 2020

My Schema looks like this (exact code here)

const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
    number:    {
        type: String,
        required: 'Number cannot be blank',
        unique: true,
    },
    messages: [
        {
            type: String
        }
    ],
    media: [
        {
            type: String
        }
    ],
    logs: [
        {
            type: String,
        }
    ]
});

const User = mongoose.model('User', userSchema);

module.exports=User;

I want to do these things below:

  • Make the logs expire after 24 hours
  • store the logs in the DB by the latest one which was created

Stack = Node + Express + MongoDB (using mongoose)