使用monk访问Mongodb时,无法使用纯JS版本加载c ++ bson扩展

时间:2014-11-26 02:29:14

标签: javascript node.js mongodb monk

当我想使用monk作为中间件来访问mongodb时,它会提示

使用纯JS版本

无法加载c ++ bson扩展

我正在运行的evn如下:

  1. OS X Yosemite
  2. 节点v0.10.32
  3. npm 1.4.28
  4. Mongodb 2.6.5
  5. 和尚0.9.1 你们中的任何人都知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

答案在Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version

转到monk index.js文件(yourProjectDirectory/node_modules/monk/node_modules/mongodb/node_modules/bson/ext/index.js

应该看起来像

try {
    // Load the precompiled win32 binary
    if(process.platform == "win32" && process.arch == "x64") {
      bson = require('./win32/x64/bson');  
    } else if(process.platform == "win32" && process.arch == "ia32") {
      bson = require('./win32/ia32/bson');  
    } else {
      bson = require('../build/Release/bson');  
    }   
} catch(err) {
    // Attempt to load the release bson version
    try {
        bson = require('../build/Release/bson');
    } catch (err) {
        console.dir(err)
        console.error("js-bson: Failed to load c++ bson extension, using pure JS version");
        bson = require('../lib/bson/bson');
    }
}

将catch块更改为

try {
...
} catch(err) {
    // Attempt to load the release bson version
    try {
        bson = require('../browser_build/bson');
    } catch (err) {
        console.dir(err)
        console.error("js-bson: Failed to load c++ bson extension, using pure JS version");
        bson = require('../lib/bson/bson');
    }
}

希望这有帮助

大卫