Mongo shell vrs mongosh

This is related to an existing thread. When I installed mongodb I ended up with mongosh. The installation of compass says the shell is deprecated. The documents on the mongoDB for load( …) state its available using Mongosh. ( https://www.mongodb.com/docs/manual/reference/method/load/#mongodb-method-load ) A 2019 thread on the forum says .load( ) worked. When I try from within Compass using Mongosh I get an error its not defined. External to Compass I get a similar response. The 2019 use of .load also doesnt appear supported. At present I dont see how I can progress on the lab given the holes in the course instruction. I have been stuck 3 days. I need some explicit help on whether the docs can be trusted ( ?) and if I am to use the mongo shell - what is it ? where is it ? and does the load(path) work with a fully declared path. Is the path escaped ( double back slash) and is the path enclosed in single or double quotes. Sorry only occasionally use Java script and my background is C#, .net SQL. Windows - so please reply in a way I can progress. Thank you !

Hi @Andrew_Watts, let me see if I can help you by clarifying a couple of things:

  • The legacy mongo shell is the deprecated one and you should use mongosh instead so if you have that installed it’s a great first step.
  • load() works in mongosh. Note, however, that you should use load("<path>") and not .load. .load "<PATH>" works as mongosh is effectively a Node.js REPL but it behaves differently so I’d recommend using load().
  • <PATH> can be an absolute path or a relative one and you don’t need to escape slashes
  • load() only works in the shell on the terminal. Currenly, the shell in Compass does not support loading external files.

Can you clarify what you mean with:

The installation of compass says the shell is deprecated.

2 Likes

Thanks this is a step closer - but I am still puzzled . I copied the 2 js files off the root as shown and under the users directory as shown. Each one failed with a different error that makes no sense to me. The error returned from the first appears as though it wants to find the file under users profile. But the path is also mangled as shown. When under users profile it tells me there’s a bad escape sequence. Single or double quote around path makes no difference.


What to do next ? Thanks !

Did you try without giving full path since you are already in that dir where your .js file resides
For your second attempt definitely some invalid character issue.Are you pasting or typing?

@Andrew_Watts I gave you slightly incorrect information. On windows where paths are delimited by backslashes, you need to use 2 of them.

2 Likes

yes ! thanks

Please make sure you do not post the same question in multiple related threads. You asked the same questions in a related thread and was answered before you asked again in this current one.

It saves time to everybody if we do not have to go through multiple related threads where the same user ask the same question, especially if the question is asked again after it has been answered.

Since this thread is marked as solved it would be nice if the other related thread is also marked as solved.

The other thread is Mongo shell - cant load loadMovieDetailsDataset.js - #9 by steevej.

Thanks in advance

From your view point I was posting and not listening to the reply. The point is the reply I was getting was inadequate and did not address the the need behind the first question. I had to dig around to realize that teh question was more than just the unzip file location but as you answered 2 years ago nuances between mongosh, mongosh with compass ( still broke for load ) and Linux vrs Windows conventions. You can berate me for not knowing to ask the right question. Rightfully so. The other issue is also plain weird - I have never seen a check box to say its the answer already checked . Today I found out that indicating its the solution means to click on the checked box and see if go intense. That’s not your problem unless you designed this non standard method. But you can expect others to get the wrath for not checking it when it starts checked. Thanks !

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.