在 MongoDB 中执行 JavaScript 文件 [英] Executing JavaScript file in MongoDB
本文介绍了在 MongoDB 中执行 JavaScript 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何在 MongoDB 中执行 JavaScript 文件.
I would like to know how to execute a JavaScript file in MongoDB.
这是我的 JS 文件中的简单代码:
This is the simple piece of code present in my JS file:
function loadNames() {
print("name");
}
从命令提示符我尝试像这样执行文件
From the command prompt I tried to execute the file like this
mongo test.js
但它显示错误:
意外的标识符
谁能向我解释我哪里出错了?
Can anyone explain to me where I'm going wrong?
推荐答案
我通常像这样运行我的测试查询,它也适用于您的示例代码.
I usually run my test queries like this, and it works with your sample code too.
mongo < test.js
这篇关于在 MongoDB 中执行 JavaScript 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文