如果没有js引擎,Mongodb无法运行map reduce [英] Mongodb cannot run map reduce without the js engine

查看:132
本文介绍了如果没有js引擎,Mongodb无法运行map reduce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mongodb作为服务的appcloud上部署了一个nodejs应用程序,我想对某些查询使用mapReduce,但出现此错误:

I deployed a nodejs app on appcloud with mongodb as service, I would like to use mapReduce for some queries but I got this error:

2016-10-21 15:45:52 [APP/0]错误ERR! {[[MongoError:如果没有js引擎,则无法运行map reduce]

2016-10-21 15:45:52 [APP/0] ERR ERR! { [MongoError: cannot run map reduce without the js engine]

swisscom appcloud上支持它吗?

Is it supported on swisscom appcloud or what?

这是我的控制器(摘录):

This is my controller (an extract):

'use strict';

const mongo = require('../mongoclient');
const paramsParser = require('../paramsParser');
const log = require('npmlog');
const faker = require('faker');
const _ = require('lodash');

const datapoints = function (router) {

  const map = function () {
    var payload = this.payload;
    if (payload) {
      payload = payload.toLowerCase().split(" ");
      for (var i = payload.length - 1; i >= 0; i--) {
        payload[i] = payload[i].replace(/[^\w\s]|_/g, "").replace(/\s+/g, " ");
        if (payload[i] && payload[i].length > 7) {
          emit(payload[i], 1); // store a 1 for each word
        }
      }
    }
  }

  const reduce = function(key, values) {
    var count = 0;
    values.forEach(function (v) {
      count += v;
    });
    return count;
  }
  
  router.get('/counts', function (req, res) {
    const filters = paramsParser.parse(req.query);

    mongo.mapReduce(map, reduce, filters)
      .then(function (data) {
        const topics = data
          .sort((a, b) => b.value - a.value)
          .slice(0, 10)
          .map(function(topic) {
            return { id: faker.random.uuid(), title: topic._id, score: topic.value }
          });
        res.json(topics);
      })
      .catch(function(err) {
        log.error(err);
        res.sendStatus(500);
      });
  });

};

module.exports = datapoints;

function mapReduce(map, reduce, filters) {
  filters = filters ? filters : defaults;
  return new Promise(function(resolve, reject) {
    client.connect(uri(), function(err, db) {
      db.collection(collection)
        .mapReduce(map, reduce, { out: { inline: 1 }, query: filters.find, limit: filters.pageSize }, function(err, docs) {
          if (err) {
            reject(err);
          }
          resolve(docs);
        });
    });
  });
}

推荐答案

您正在使用Swisscom的基于Docker的MongoDB服务.

You are using Swisscom's Docker based MongoDB service.

Swisscom从 security.javascriptEnabled 开始了mongod.

Swisscom started mongod with security.javascriptEnabled

启用或禁用服务器端JavaScript执行.什么时候 禁用后,您将无法使用执行服务器端执行的操作 JavaScript代码,例如$ where查询运算符mapReduce 命令以及db.collection.mapReduce()方法,组命令和 db.collection.group()方法.

Enables or disables the server-side JavaScript execution. When disabled, you cannot use operations that perform server-side execution of JavaScript code, such as the $where query operator, mapReduce command and the db.collection.mapReduce() method, group command and the db.collection.group() method.

Swisscom出于安全原因启用了该标志.这是强化MongoDB的最佳实践. Swisscom公开接受技术辩论和讨论.也许Swisscom错过了一个重要的事实?

Swisscom enabled that flag because of security. It's a best practise for hardening MongoDB. Swisscom is open for technical arguments and discussions about that. Maybe Swisscom misses an important fact?

security:
   authorization: enabled
   javascriptEnabled: false

Swisscom提供其他MongoDB服务(不在Docker容器中,带有复制的3个专用VM).那里没有这个限制.

Swisscom offers an other MongoDB service (not in docker container, 3 dedicated VMs with replication). There you don't have this limitation.

$ cf m -s mongodbent
Getting service plan information for service mongodbent as admin...
OK

service plan   description                                                                                                 free or paid   
small3rs       Replica Set with 3 data bearing nodes with 32 GB memory, 320 GB storage, unlimited concurrent connections   paid   
medium3rs      Replica Set with 3 data bearing nodes with 48 GB memory, 480 GB storage, unlimited concurrent connections   paid   
large3rs       Replica Set with 3 data bearing nodes with 64 GB memory, 640 GB storage, unlimited concurrent connections   paid 

通过该计划,您将获得MongoDB的企业版,并可以访问 Ops Manager .在Ops Manager中,您将看到带有MongoDB指标的漂亮HTML5图形.很好的 db.runCommand({serverStatus:1})的GUI前端历史.

With this plan you will receive Enterprise version of MongoDB and access to Ops Manager. In Ops Manager you will see nice HTML5 graphs with MongoDB metrics. It's nice GUI frontend for db.runCommand( { serverStatus: 1 } ) with history.

这篇关于如果没有js引擎,Mongodb无法运行map reduce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆