Blog > detail

Just my tiny mind

Error: can't use sharded collection from db.eval

26-2-2012 Admin General 2 Comments

As the title says. This error occurs when you try to use db.eval in a sharded collection. I find it when I tried to run my saved js function in mongoDB.


For me, instead of using db.eval, i tried using db.loadServerScripts();. And whola, it is solved db.eval problem.


Here is my code:


db.system.js.save({

    _id: "testread",

    value: function (user_id) {

        return get_users_detail = db.getCollection('wp_users').findOne({ID:user_id});


    }

});


db.loadServerScripts();

testread(1);


//db.eval("testread(1);");//error eval


Hope this simple tips can help you solve your error "can't use sharded collection from db.eval".