【问题标题】:How to perform MongoDB CRUD operations through javascript?如何通过 javascript 执行 MongoDB CRUD 操作?
【发布时间】:2014-11-23 22:45:51
【问题描述】:

我正在尝试自动对标签范围进行修改。但我在第一个 'db.tags.remove...' 处不断收到“SyntaxError: Unexpected identifier at ...”错误。

...
today = yyyy+mm+dd;
balancing = sh.getBalancerState();

if (! balancing) {
    conn = new Mongo("mongoserver.mydomain.com:27017");
    db = conn.getDB("config");
    db.tags.remove({ _id: { ns: "mydb.mycoll", "min": { "day:" MinKey }}, tag: "LTS" });
    db.tags.remove({ _id: { ns: "mydb.mycoll", "max": { "day:" MaxKey }}, tag: "STS" });
    sh.addTagRange("mydb.mycoll", { day: MinKey }, { day: today }, "LTS");
    sh.addTagRange("mydb.mycoll", { day: today }, { day: MaxKey }, "STS");
};
...

欢迎任何帮助,

谢谢,

格雷格。

【问题讨论】:

  • 这是什么语言?这看起来像是一个编程问题——属于 Stackoverflow。
  • 由 mongo shell 运行的 shell javascript。有没有办法把它移到stackoverflow?
  • 我不是 Javascript 语言大师,但也许应该是 db.tags().remove

标签: replication mongodb sharding


【解决方案1】:

错位“ - 我花了一段时间才看到它!

db.tags.remove({ _id: { ns: "mydb.mycoll", "min": { **"day:"** MinKey }}, tag: "LTS" });
db.tags.remove({ _id: { ns: "mydb.mycoll", "max": { **"day:"** MaxKey }}, tag: "STS" });

改成"day" :

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多