Small Wins in MongoDB Compass

By Coding Feline ยท

I spend most of my database time in code, through Prisma, but every now and then I need to look at the data directly. For that, MongoDB Compass has become my tool of choice, and two features in particular have saved me more time than I expected.

The first is renaming a collection. I had a collection whose name no longer matched what it held, and I assumed renaming it would mean exporting, recreating and importing. In Compass, it is simply an option in the collection's menu. Before doing it, though, it is worth remembering that your code still points at the old name. With Prisma, that means updating the model, or adding @@map("new_name") so the model name and the collection name can differ.

The second is generating queries from plain English. Compass can turn a sentence such as "journals from December 2024 sorted by newest first" into a proper filter and sort:

{ "date": { "$gte": { "$date": "2024-12-01" }, "$lt": { "$date": "2025-01-01" } } }

It needs the generative AI features switched on in the settings and an Atlas login, but once that is done, it is a surprisingly good way to learn the query syntax. I write what I want, look at what it produces, and gradually the operators stop looking like a foreign language.

I still check every generated query before trusting it, especially anything that updates or deletes. But for exploring data and answering quick questions, describing what I want and reading the result back is far faster than looking up the syntax each time.