我正在尝试针对mongodb副本集运行javascript文件,但它在第2行失败并出现以下错误:
MongoDB shell version: 2.4.5
connecting to: test
Tue Jan 21 09:00:01.702 JavaScript execution failed:
ReferenceError: conn is not defined at /opt/mongo-scripts/views-by-date.js:L2
failed to load: /opt/mongo-scripts/views-by-date.js
这是脚本的内容:
var conn = new Mongo();
var db = conn.getDB("main"); // line 2
var date = ISODate();
...
这是我在bash shell上运行的命令:
mongo /opt/mongo-scripts/views-by-date.js
我假设,虽然可能错了,但它与副本集有关,因为脚本适用于我的本地非副本集mongo实例。
答案 0 :(得分:1)
这应该可以解决问题:
var db = db.getSisterDB("main")