Running a JS file directly from the Mongo shell using the query
mongo localhost:27017/west createSumCollection.js
has resulted in an error:
"uncaught exception: SyntaxError: unexpected token: identifier : @(shell):1:6"
The content of CreateSumCollection.js includes basic database usage and db.createCollection with a simple object id and another field.
What could be causing this issue? The same script runs perfectly when executed directly in the mongoshell.
Attempting to load("C:/mongodb/data/db/createSumCollection.js") failed due to the "use west" statement. Removing this statement allowed the load to work. I am curious about the difference between load and mongo localhost:27017/west createSumCollection.js and how to successfully run the JS file directly.