在Debian中运行包含load()和print()函数的JS脚本

Run JS script containing load() and print() functions in Debian

本文关键字:函数 print JS 脚本 Debian 运行 包含 load      更新时间:2023-09-26

我需要在Debian中运行一个map reduce JS脚本:该脚本从本地运行的MongoDB实例(mongod)中读取和写入,并创建一个类似条目的表
问题是脚本包含加载打印函数:

load("map-reduce-.../somefile.js");

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
...
var db = new Db('results', new Server('localhost', 27017));
// Connect to db
...
var collectionName = "labelgroups"; //collection to store last executions
var testset = "testset"; //collection target of map-reduce
var mapReduceName = "timedmapReduce"; //output collection
var collection = db.getCollection(collectionName);
if (collection.exists() == null) {
    // Create collection
    print("mapReduce collection is being created");
    db.createCollection(collectionName);
    collection = db.getCollection(collectionName);
    collection.insert({ ... });
} else { ... }

我尝试使用NodeJS,但安装这些功能的模块失败了。我还尝试使用Rhino运行它,Rhino处理打印和加载功能,但我无法使用MongoDB模块。
如何在Debian中运行此脚本?

为此使用console.log()。

示例:

console.log('This line will be written to stdout');