V
V
vleypi2021-10-03 16:50:11
MongoDB
vleypi, 2021-10-03 16:50:11

How to delete a specific line in a post automatically after a certain time?

If I figured out how to completely delete the entry itself, after a certain time, using:
createdAt: { type: Date, expires: 60, default: Date.now }

But what if I want to delete the owner line after a certain time?

const schema = new Schema({
    createdAt: { type: Date, expires: 60, default: Date.now }, /*с помощью чего удаляется вся запись*/
    name:{
        type:String,
        required: true,
        unique:true
    },
    password:{
        type:String,
        required: false,
    },
    owner: {
        type: String,
        required: true,
    }, /*конкретная строчка, которую я хочу удалять через определенное время, createdAt: expires 60 не помог */
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RaShe, 2021-10-07
@RaShe

This will not work)
Possible solution:
Create a new owners collection where the owner date itself will be, which will be deleted after a certain time, and the owner's id will be in the main schema. When you want to know if the owner exists then just try to find it by id, or you can even populate.
I don't know exactly your usecase, but maybe you don't need to delete anything, or you can create another ownerDate field that will show the date or expiry.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question