Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

298
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda