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

时间:2022-04-16 21:06:51

I need to run a map-reduce JS script in Debian: the script reads from and writes to a MongoDB instance running locally (mongod) and creates a table of similar entries.
The problem is that the script contains load and print functions:

我需要在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 { ... }

I tried using NodeJS but I failed installing the modules for those functions. I also tried to run it using Rhino, which handles print and load functions but I can't manage to get a MongoDB module working on it.
How can I run this script in Debian?

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

1 个解决方案

#1


0  

Use console.log() for this.

为此使用console.log()。

Example:

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

#1


0  

Use console.log() for this.

为此使用console.log()。

Example:

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