我从git获得了mongo-sync,然后尝试使用自述文件。
我编码test.js就像那样:
var Server = require("mongo-sync").Server;
var server = new Server('127.0.0.1');
var result = server.db("test").getCollection("posts").find().toArray();
console.log(result);
server.close();
我使用common-node test.js
来运行
Error: yield() called with no fiber running
at DB.<anonymous> (/home/zhoubin/project/job/tools/node/node_modules/mongo-sync/lib/mongo-sync.js:23:18)
at new DB (/home/zhoubin/project/job/tools/node/node_modules/mongo-sync/lib/mongo-sync.js:59:23)
at Server.db (/home/zhoubin/project/job/tools/node/node_modules/mongo-sync/lib/mongo-sync.js:48:10)
我的代码出了什么问题?
这是monog-sync / lib / mongo-sync.js中的代码:
var Fiber = global.Fiber || require("fibers");
var mongodb = require("mongodb");
exports.ObjectId = mongodb.ObjectID;
function sync(obj, fn) {
return function() {
var args = Array.prototype.slice.call(arguments);
var result;
var fiber;
args.push(function(error, value) {
result = error || value;
if (fiber) {
fiber.run(result);
} else {
fiber = true;
}
});
var o = this[obj];
o[fn].apply(o, args);
if (!fiber) {
fiber = Fiber.current;
Fiber.yield();
}
if (result instanceof Error) {
throw new Error(result.stack + '\nFollowed by:');
}
return result;
};
}