Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

297
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda