Meteor JS: How to skip Mongo data automatically?

Is there a way to configure the collection in MongoDb to automatically expire MeteorJS? I saw how to do this from the Mongo website , but was not sure how to do it from Meteor:

  Tasks.insert({
    text: text,
    createdAt: new Date(),
  });

  //None of these work:
  Tasks.ensureIndex( { "createdAt": 1 }, { expireAfterSeconds: 2 } );
  Tasks._ensureIndex( { "createdAt": 1 }, { expireAfterSeconds: 2 } );
  Tasks.createIndex( { "createdAt": 1 }, { expireAfterSeconds: 2 } );
+4
source share
1 answer

Why not just delete it yourself? inserts second parameter is a callback inside which you can use setTimeoutto wait 2 seconds:

Tasks.insert({
  text: text,
  createdAt: new Date(),
}, function(err, _id) {
  if (_id != null) {
    Meteor.setTimeout(function() {
      Tasks.remove(_id);
    }, 2000); // 2 seconds delay
  }
});
+3
source

All Articles