Applying data retention in MongoDB when using Siddhi

Approach Overview

Creating of an ISODate field

{date: {$exists: false}},
$set: {
date: { $toDate: '$dt'}
db.test.insert([{text: "b2", dt: new Date().getTime()}]);

Creating an index with TTL in MongoDB

date: 1
name: "idx_ttl_date",
expireAfterSeconds: 5

Automating the Process

  1. To get a list of all collections in database
  2. To check if they have index with TTL
  3. To create the field which is used in the index
db.getCollectionNames(); -- returns a list of collections
db.test.getIndexes(); -- returns indexes of a collection



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alexander Goida

Alexander Goida

All opinions are my own || Software Developer, learner, perfectionist and entrepreneur-kind person, nonconformist. Always seeks for the order and completeness.