4

I am currently trying to design a schema structure with mongoose which looks like the following:

var hubSchema = new mongoose.Schema({
   //some other properties
    dataStream: {
        dataType: String,
        dataPoints: [{
            createdAt: { type: Date, expires: '7d'}
            data: {}
        }],
        storeStrategy: {
            type: String,
            enum: storeStrategies
        }
    },
});

The mongoose API docs say that:

Sub-documents enjoy all the same features as normal documents. The only difference is that they are not saved individually, they are saved whenever their top-level parent document is saved.

I want dataPoints to be an array of sub-documents and each sub-document should have TTL set just as a normal document. Having said that, I found out from other posts that it is not possible to set 'expires' for sub-documents. So my question is: Should I create a separate model for dataPoints and store a references here or I should implement some custom strategy for deleting sub-documents keeping this kind of structure?

Community
  • 1
  • 1

0 Answers0