首页 文章

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

提问于
浏览
0

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

使用纯JS版本无法加载c bson扩展名

我正在运行的evn如下:

  • OS X Yosemite

  • 节点v0.10.32

  • npm 1.4.28

  • Mongodb 2.6.5

  • 和尚0.9.1你们中的任何人都知道如何解决这个问题吗?

1 回答

  • 2

    答案在[Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version](https://stackoverflow.com/questions/28651028/cannot-find-module-build-release-bson-code-module-not-found-js-bson)

    去和尚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');
        }
    }
    

    希望这可以帮助

    大卫

相关问题