Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

300
Views
Call a java script file in mongodb shell

I tried to run a JS file directly from the Mongo shell by using the query

mongo localhost:27017/west createSumCollection.js

However I keep getting the error

"uncaught exception: SyntaxError: unexpected token: identifier : @(shell):1:6"

The contents of CreateSumCollection.js are a simple use database and db.createCollection with a simple object id and another field.

Any idea what I am missing here? If I run the same script in the mongoshell directly it works perfectly.

I tried load("C:/mongodb/data/db/createSumCollection.js") and it failed because of the use west statement inside the .js file. So after removing that, the load worked. My question is what is the difference between load and mongo localhost:27017/west createSumCollection.js and how do i get the js to be run directly.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

use is a helper that is only available in the interactive shell.

In the interactive shell (and via load) you might run:

use my_database
db.collection.find()

The equivalent in a javascript file on the command line would be:

db.getSiblingDB("my_database").collection.find()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!