mongodb-js / vscode

Connect to MongoDB and Atlas and directly from your VS Code environment, navigate your databases and collections, inspect your schema and use playgrounds to prototype queries and aggregations.
https://marketplace.visualstudio.com/items?itemName=mongodb.mongodb-vscode
Apache License 2.0
327 stars 58 forks source link

Ability to use the Load command in the playground #263

Open MullinsN opened 3 years ago

MullinsN commented 3 years ago

Feature Request

It would be really useful to use the load command within the playground.

Detailed Description

It is something that is not supported since there is a message that indicates that it isn't so, when I try to use it, though it could be a generic message for all unsupported commands.

load("validateLab1.js");

Context

At the moment going through the aggregation pipeline course again, and it's uses the load command for the validation proportion of the labs to return the number that you enter if the aggregation pipeline is correct.

I can copy the validate code into the playground and run it that way, but it means my playground becomes full of validate code and not the actual code of importance, the aggregation pipeline.

The more people who use the extension within better support earlier on (such as within VSC), will have a more joyful experience with MongoDB, because it is a real pain in the arse using the command shell, with the aggregation pipeline.

The inbuilt shell that is used on the M001 basics course, is again the wrong way to go forward.

Possible Implementation

Who knows how it's going to be implemented, it's easier to suggest things than have to do the work to create them.

mmarcon commented 3 years ago

@MullinsN we are currently planning the work for load() in mongosh. Once we have it done in mongosh it should mostly work out of the box in playgrounds.

MullinsN commented 3 years ago

Thank you for the notification.

Hopefully the implementation will be painless as possible.

Out of interest, you mention mongosh, this is different to the mongo shell? .... Ah this is you ?

https://www.mongodb.com/blog/post/introducing-the-new-shell

It is good to see that it's been broken out of the mongo command for more rapid development.

Do you know when the mongosh will be able to provide understanding of it's context so it can prompt for comparison query operators via intellisense?

mmarcon commented 3 years ago

Yes, that is me :)

mongosh is the new MongoDB Shell. We rebuilt from scratch to improve the user experience and to make it embeddable in other places. You can still install it as a standalone CLI command and use it in the terminal but you can find it also embedded into Compass and it is the runtime that powers playgrounds in VS Code.

Over time, you might see it available also in other places, and we will expand its functionality as we expand our cloud platform offering on Atlas.

Intellisense is a topic we are exploring from different angles and we are looking at different options to make it smarter. Happy to chat about this if you'd like. Feel free to grab a slot in my calendar.

MullinsN commented 3 years ago

I will not take any of your time up, though thanks for the offer.

I did notice that on 0.42 you have added a refresh of documents icon. Slightly related, how does the extension (mongosh) work out shape of the document? Does it work in a similar way to the analyse tool in compass?

The reason I am thinking not, is that I had a simple couple of test documents, where the intellisense picked up the first document field names, but not the second one.

If you do implement compass like 1000 documents analysis model, make the analysis work automatically the first time of connection to a collection, cache it, and use that cached version, unless the user presses "refresh" document schema. It is a small quibble I have with compass, that each time you connect to compass, the analyze schema doesn't remember the previous document shape of a collection.

Anemy commented 3 years ago

@MullinsN Currently we're parsing the shapes of documents using this same module compass uses: https://github.com/mongodb-js/mongodb-schema

The intellisense autocomplete is not using the same schema sample as the tree view collections schema at the moment. I do like what you're getting at there though that bringing them together could allow users to be more in control of the cache. Currently the autocomplete parses one document and the tree view schema parses 10. (At some point we'd like to make this a configurable setting).

Thanks for all the feature requests - hopefully we can get to all of them in time :)

libinvarghese commented 2 years ago

Even after load is supported in mongosh, I am still unable to use load in the playground. I get the following error.

[COMMON-90002] load is not currently implemented for this platform

I am able to use load in mongosh.

vscode:                 1.55.0
mongodb.mongodb-vscode: v0.6.10
Using MongoDB:          4.4.1
Using Mongosh:          1.1.0
macOS:                  10.13.6
mmarcon commented 2 years ago

Hi @libinvarghese. We have not exposed the load() implementation in VS Code playgrounds yet. Can you share a bit about your use-case?

yilmazdurmaz commented 2 years ago

@mmarcon have you seen MongoDB University courses? this load ability would come in handy when validating course material, if it worked :)

anyways, the extension seems handy itself but with growing query size, it will not be feasible to use it anymore unless this load functionality is made to work. it is the way to write long functions into separate files and import them into the playground (the shell for mongo/mongosh).

And also the extension itself is not called "a playground for mongodb". That means this extension has a future to be a great tool we can use without leaving VSCode ever, and load ability is one key feature we need.