【问题标题】:Run JS script containing load() and print() functions in Debian在 Debian 中运行包含 load() 和 print() 函数的 JS 脚本
【发布时间】:2016-05-15 22:55:59
【问题描述】:

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

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 运行它,它处理打印和加载功能,但我无法让 MongoDB 模块在其上运行。
如何在 Debian 中运行此脚本?

【问题讨论】:

    标签: javascript node.js mongodb rhino


    【解决方案1】:

    为此使用console.log()。

    例子:

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

    【讨论】:

      猜你喜欢
      • 2016-11-28
      • 1970-01-01
      • 2019-05-29
      • 1970-01-01
      • 2021-05-06
      • 1970-01-01
      • 2013-01-29
      • 2018-08-04
      • 2015-08-27
      相关资源
      最近更新 更多