vscode icon indicating copy to clipboard operation
vscode copied to clipboard

playgrounds alway try to execute in db test

Open moisesbites opened this issue 3 years ago • 4 comments

Bug Report

Current Behavior

Any command I run, even if I set the connection string correctly, the system returns an "unauthorized error in the test database". This error does not occur in Compass or in the application with the same connection data.

"not authorized on test to execute command" for all commands, since aggregate, find, insert, etc...

Environment

  • node.js / npm versions: node v16.11.0 / npm 8.3.0

  • OS: [e.g. OSX 10.13.4, Windows 10] Linux Mint 20.1 Cinnamon / Kernel 5.13.0-21-generic

moisesbites avatar Dec 14 '21 19:12 moisesbites

Hello @moisesbites!

Can you share with us what exactly you are doing? What database are you trying to run commands in, and what happens if you add use('database_name'); at the top of your playground? Does VSCode list databases and collections in the menu on the left of the screen?

addaleax avatar Dec 15 '21 10:12 addaleax

Hello @moisesbites!

Can you share with us what exactly you are doing? What database are you trying to run commands in, and what happens if you add use('database_name'); at the top of your playground? Does VSCode list databases and collections in the menu on the left of the screen?

Hello @addaleax

  System:
    OS: Linux 5.13 Linux Mint 20.2 (Uma)
    CPU: (4) x64 Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz
    Memory: 13.00 GB / 23.37 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.11.0 - ~/.nvm/versions/node/v16.11.0/bin/node
    npm: 8.3.0 - ~/.nvm/versions/node/v16.11.0/bin/npm
  IDEs:
    Nano: 4.8 - /usr/bin/nano
    VSCode: 1.63.1 - /usr/bin/code
    MongoDB for VS Code v0.7.0
    MongoDB Compass 1.28.4
  Browsers:
    Chrome: 96.0.4664.110
    Chromium: 96.0.4664.93
    Firefox: 95.0
  App:
    mongoose: 6.1.2

I have a container running mongodb official image (mongo:5). I'm programming the App using nodejs and express in the backend Api.

The application connects normally to mongodb and executes all commands via mongoose normally. All commands in MongoDb Compass normally work with the same connection string. However, through the MongoDB extension to VS Code, every command executed is not authorized in the 'test' database. Even using the "use" command and configuring the correct database. However, in the object tree, I access everything normally. But in the editor's text screen, it gives an error.

mongodb://user:password@localhost:27117/sasu?authSource=sasu&readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false

use('sasu');

db.mime_types.findOne({"_id": 'text/html'})

image

I did further testing and found that if I select the entire command, including "use", the extension executes the command correctly. But if I run "use" first and then run the mongoDB command separately, I get an access error. But that didn't happen before, in previous versions.

I always use the "use" command at the top, but I run each command separately, just to test the commands, check the outputs. The error occurs that way.

For example: image

image image

Running with everything selected as a single big command, the error does not occur. It seems to me that the extension is not keeping the database connected (in "use" command) between commands.

For example: image

moisesbites avatar Dec 15 '21 13:12 moisesbites

@moisesbites Thanks for the reply! It is currently the expected behavior that if you run only a subset of statements, and that subset omits the database selection, then no database is explicitly selected.

I do agree that it seems like a bug that the database is not chosen based on the connection string you provided. I’ve opened https://jira.mongodb.org/browse/VSCODE-316 to track that.

addaleax avatar Dec 16 '21 10:12 addaleax

@addaleax Thank you. I appreciate your help. For while, running all commands with "use" it's working. So, I will wait for the fix that. This extension it's very useful for me. I just use Compass if this extension is not working.

moisesbites avatar Dec 16 '21 13:12 moisesbites

The issue is not reproducible anymore. Feel free to reopen if you experience it again.

alenakhineika avatar Feb 05 '24 13:02 alenakhineika