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:
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.
mongosh
executable should be in your PATH
Packer:
use { 'jrop/mongo.nvim' }
: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 db.some_db.find({})
:Mongoquery
- use the current buffer as the Mongo query:'<,'>Mongoquery
- use the current selection as the Mongo query:Mongoexecute
- like :Mongoquery
but 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
:Mongoexecute
):Mongoedit --coll=some_collection --id=SOME_ID
- shorthand option (--coll
instead of --collection
):Mongoedit
- with no parameters, the plugin will try to infer
the collection and relevant id by doing a few things:
:Mongoquery
_id
is extracted based on the current cursor position using
the current Treesitter context for the current buffer:Mongorefresh
- refresh data in the current bufferNovember 4, 2022
November 2, 2022
:Mongoedit
is run without --coll
/--id
, try to infer the collection
from the data stored in the previous bullet, and also try to infer the nearest
_id
(based on cursor position) using the current Treesitter context.October 31st, 2022
:Mongorefresh
command:Mongoconnect
more robust: if there are multiple DBs, show them in a
selector to the user via vim.ui.select(..)
Copyright (c) 2022 jrapodaca@gmail.com
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.