How to Create a MongoDB TTL Index on Mobile

Expire old documents automatically without a laptop. Here's how to create a MongoDB TTL index - plus unique and sparse indexes - straight from your phone.

Short answer: to create a MongoDB TTL index from your phone, open a collection in Byson, go to Indexes, tap Create, add a single date field, toggle TTL on, and set the expireAfterSeconds value. Byson auto-names the index and builds it with a raw MongoDB command on both Android and iOS.

Disclosure: we make Byson, a mobile MongoDB client with built-in SSH tunneling. The steps below describe Byson's Index Create screen, but the underlying MongoDB commands are the same in any client.

Byson create-index screen with Unique, Sparse and TTL options

What is a TTL index, and why use one?

A TTL (time to live) index tells MongoDB to delete documents automatically once they reach a certain age. You point it at a single date field and set how many seconds a document should live; a background process then expires the document after that many seconds. It's the standard way to handle sessions, one-time tokens, logs, and any data that should clean itself up - and you can set the whole thing up from a phone.

TTL, unique, and sparse: what each flag does

Byson's Index Create screen supports multi-key indexes (each key ascending or descending) plus three flags. Here's what each one does:

Index flagWhat it doesTypical use
UNIQUEEnforces no duplicate values for the indexed fieldEmails, usernames, external IDs
SPARSEOnly indexes documents that have the field; skips the restOptional fields present on a subset of documents
TTLExpires documents after N seconds via expireAfterSecondsSessions, tokens, logs, temporary data

One rule worth remembering: a TTL index applies to a single date field and expires documents after the number of seconds you set. It isn't a compound or multi-field rule - point it at one timestamp.

How to create a TTL index from your phone

The flow takes about a minute in Byson:

  1. Open the collection you want to index.
  2. Tap Indexes to see the existing indexes.
  3. Tap Create.
  4. Add your date field as a key and pick a direction (ascending or descending).
  5. Toggle TTL on and set the expireAfterSeconds value (for example, 86400 for one day).
  6. Review the auto-generated index name - Byson names it for you.
  7. Tap Create. Byson runs its validation rules, then builds the index with a raw MongoDB command.

The same screen handles unique and sparse indexes: instead of TTL, toggle UNIQUE to enforce no duplicates, or SPARSE to index only documents that have the field. You can combine fields for multi-key indexes too.

Verifying and managing your indexes

After you create an index, it appears in the index list with its size and real usage pulled from $indexStats, so you can see whether queries actually hit it. Byson shows badges - UNIQUE, SPARSE, TTL - so the type is obvious at a glance.

Dropping an index is just as direct, with one guardrail: if the index is larger than about 50MB, Byson asks you to type its name to confirm before it drops it. That safeguard exists because dropping a large index on a busy collection is not something you want to do by accident from a phone.

That's it

A TTL index is the cleanest way to let MongoDB expire stale data on its own, and you no longer need a desktop tool to set one up. Point Byson's Index Create screen at a date field, set expireAfterSeconds, and let MongoDB handle the cleanup - all from your phone.

Official reference: MongoDB - TTL Indexes.

Create MongoDB indexes from your phone with Byson

Byson is a mobile MongoDB client with built-in SSH tunneling - free on Google Play and the App Store. The BYO AI Copilot is an optional bonus. Build TTL, unique, sparse, and multi-key indexes with raw MongoDB commands and live usage stats.

FAQ

Can I create a TTL index from a mobile app?

Yes. Byson's Index Create screen lets you build a TTL index from your phone on Android or iOS. Add a single date field, toggle TTL on, set the expireAfterSeconds value, review the auto-generated name, and tap Create. Byson runs the raw MongoDB command for you.

What is a sparse index in MongoDB?

A MongoDB sparse index only indexes documents that actually have the indexed field. Documents missing the field are skipped, which keeps the index smaller. In Byson you enable it with the SPARSE flag on the Index Create screen, and indexes show a SPARSE badge in the list.

How do I create a unique index in Byson?

Open a collection, go to Indexes, tap Create, add your field with a direction, then toggle the UNIQUE flag to enforce no duplicate values. Byson auto-generates an index name, applies its validation rules, and creates the index with a raw MongoDB command. It then shows a UNIQUE badge in the index list.

Related: MongoDB query profiler on mobile →

Related: The best mobile MongoDB GUI →