NeoVim frontend for mongosh
mongo.nvim
A NeoVim frontend for mongosh
Note: I developed/tested this plugin on NeoVim 0.7.2, and 0.8.0. I have not
tested it on any other versions
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
: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.
Requirements
- The
mongoshexecutable should be in yourPATH
Installation
Packer:
use { 'jrop/mongo.nvim' }
Commands
:Mongoconnect [--host=localhost:27017] --db=some_db- this is a convenience
:Mongocollections- open a buffer that lists the collections in the DB we
<Enter> on a collection to open a
stub-query.
:Mongoquery db.some_db.find({}):Mongoquery- use the current buffer as the Mongo query:'<,'>Mongoquery- use the current selection as the Mongo query:Mongoexecute- like:Mongoquerybut do not display the result set in a
:Mongoedit --collection=somecollection --id=SOMEID- a shorthand for
db.*.replaceOne(...) query so
that the document can easily be edited (by a subsequent call to
:Mongoexecute)
:Mongoedit --coll=somecollection --id=SOMEID- shorthand option (--coll
--collection)
:Mongoedit- with no parameters, the plugin will try to infer
:Mongoquery
- the nearest _id is extracted based on the current cursor position using
the current Treesitter context for the current buffer
:Mongorefresh- refresh data in the current buffer
TODO
- [X] Remove dependency on vim-prettier
- [ ] Consider supporting pagination
- [ ] Consider writing a custom data format (built on top of EJSON) that
Changelog
November 4, 2022
- Remove JS-style output of queries as it was too error-prone. Use EJSON
November 2, 2022
- Utilize Treesitter when executing a query to keep track of what collection a
- When
:Mongoeditis run without--coll/--id, try to infer the collection
_id (based on cursor position) using the current Treesitter context.
October 31st, 2022
- Make certain operations "refreshable" and add the
:Mongorefreshcommand - Fix a bug when the resulting executed expression returns undefined (e.g., IIFE
- Make
:Mongoconnectmore robust: if there are multiple DBs, show them in a
vim.ui.select(..)
Licence (MIT)
Copyright (c) 2022
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.