vim-dadbod-ui icon indicating copy to clipboard operation
vim-dadbod-ui copied to clipboard

MongoDB filtetype javascript

Open chrstnwhlrt opened this issue 1 year ago • 14 comments

Every query buffer is automatically set to filetype sql (which works hand in hand with the autocomplete plugin). Using MongoDB as my main database type filetype javascript would be more helpful (as the lsp can kick in and help with formating the queries for example). Is there any way to configure the filetype? (:set filetype=javascript does the job)

chrstnwhlrt avatar Sep 23 '23 20:09 chrstnwhlrt

I'm not an lua programmer but this is the place where the filetype of the db which is used for the new buffers defaults to sql correct?

image

chrstnwhlrt avatar Sep 25 '23 07:09 chrstnwhlrt

could you please help me with my problem? I'm running mongodb with docker, from offical mongodb image. I can connect to this db with studio3t But when i'm tring to connect to this db with DBUI i have error "Error connecting to db mongo: 'mongosh' executable not found" My url is: mongodb://localhost:27017 (this url also in studio3t) Looked to google, can't find answer. Where is my problem? Thanks

BioWare avatar Oct 18 '23 05:10 BioWare

Hi @BioWare. You need to install the mongosh. If you use ubuntu, you can follow this steps:

  1. sudo apt-get install gnupg curl
  2. curl -fsSL https://pgp.mongodb.com/server-7.0.asc |
    sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg
    --dearmor
  3. sudo touch /etc/apt/sources.list.d/mongodb-org-7.0.list
  4. echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
  5. sudo apt-get update
  6. sudo apt install mongodb-mongosh

Reference: https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/#install-mongodb-community-edition

gusilva avatar Oct 19 '23 09:10 gusilva

Hi @BioWare. You need to install the mongosh. If you use ubuntu, you can follow this steps:

  1. sudo apt-get install gnupg curl
  2. curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
  3. sudo touch /etc/apt/sources.list.d/mongodb-org-7.0.list
  4. echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
  5. sudo apt-get update
  6. sudo apt install mongodb-mongosh

Reference: https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/#install-mongodb-community-edition

Hello @gusilva thanks for your answer. So even if im using docker i have to install mongosh localy right?

BioWare avatar Oct 19 '23 10:10 BioWare

@BioWare, I suppose you use a docker container to provide a MongoDB server. That being said, to connect to this MongoDB container, you need a Mongo client. Dadbod uses mongosh or mongo, which should be installed in the environment where your nvim is running. Studio3T has its Mongo client packaged with its program, that's why you are able to connect via Studio3T to the MongoDB container.

gusilva avatar Oct 19 '23 12:10 gusilva

@BioWare, I suppose you use a docker container to provide a MongoDB server. That being said, to connect to this MongoDB container, you need a Mongo client. Dadbod uses mongosh or mongo, which should be installed in the environment where your nvim is running. Studio3T has its Mongo client packaged with its program, that's why you are able to connect via Studio3T to the MongoDB container.

got it. Thanks for your help

BioWare avatar Oct 20 '23 04:10 BioWare

I have the same problem as the original ticket author. I work almost exclusively with mongodb and the sql filetype in the query window is making it more difficult than it has to be.

If the query pane filetype could be switched to javascrip, it will allow block comments from plugin to use the correct prefix, apply autoformatting correctly etc. At the moment the editor thinks the blank query window is of type sql and will do block comments with -- instead of //.

jacoatvatfree avatar Jul 11 '24 13:07 jacoatvatfree

I pushed a change to master that should make mongodb query buffers a js filetype.

kristijanhusak avatar Jul 11 '24 14:07 kristijanhusak

Is there a way with the new js filetype change to load omnifunc completions for the DBUI only? The sql filetype was a bit more exclusive but js is not as distinguishable.

mvllow avatar Jul 16 '24 15:07 mvllow

I'm not sure if and how well does mongodb autocompletion works. We could set some buffer variable and distinguish by that, but first we need to generally test the mongodb support both here and on completion. I'm not a mongodb user, so I'm open to PRs to address any potential issues.

kristijanhusak avatar Jul 16 '24 16:07 kristijanhusak

That makes sense, looks like the table names are the only items completed at the moment so not a huge deal either way.

Having a more generalised way to detect DBUI running could also give an alternative for setting the default keymaps as now <Leader>W is not mapped, for example. Easy to manually set these as the user but wanted to note that here too :)

mvllow avatar Jul 16 '24 16:07 mvllow