mongo.nvim: A NeoVim frontend for mongosh.
MongoDB Compass is a great tool, but when you want to edit a large document, it really begins to slow down, and on top of that, a Vimmer really begins to miss all the editing capabilities not found in Compass‘ document editor. Enter this plugin: I wanted something that would let me:
- Write MongoDB queries and execute them from Vim
- Edit documents with ease and write them back to the database simply
This plugin does just that by acting as a frontend for the excellent mongosh. Send mongosh scripts to be executed with
:Mongoquery and have the results displayed in a temporary unlisted buffer. Generate the appropriate „replaceOne(…)“ script for easy single-document editing with the
:Mongoedit --collection=... --id=...command.
:Mongoconnect [--host=localhost:27017] --db=some_db– this is a convenience for „caching“ a connection string globally so that you don’t have to repeatedly set the DB you want to connect to for each query you run: use this when you need to connect to a specific DB across several repeated calls
:Mongocollections– open a buffer that lists the collections in the DB we are currently connected to. Press
<Enter>on a collection to open a stub-query.
:Mongoquery– use the current buffer as the Mongo query
:'<,'>Mongoquery– use the current selection as the Mongo query
:Mongoquerybut do not display the result set in a buffer: just print the response to Vim’s messages
:Mongoedit --collection=some_collection --id=SOME_ID– a shorthand for finding a given document, and generating a
db.*.replaceOne(...)query so that the document can easily be edited (by a subsequent call to
:Mongoedit --coll=some_collection --id=SOME_ID– shorthand option (