1

i was got the mongo-sync from git,and then take a try with readme.

i codeing test.js like that:

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();

i use common-node test.js to run

then i got the return :

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)

what's wrong with my code?

this is mongo-sync's link

this is broking code in 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;
  };
}
Shura
  • 25
  • 1
  • 7
  • your code worked for me without problems. What versions of node, common-node and mongo-sync are you using? On what system? – soulcheck Apr 02 '14 at 08:18
  • i was used `common-node test.js` ,my OS is fedora17,node version is v0.10.25 – Shura Apr 02 '14 at 08:49

0 Answers0