Search code examples
replicationmongodbsharding

How to perform MongoDB CRUD operations through javascript?


I'm trying to automate modifications made on tag ranges. But I keep getting an "SyntaxError: Unexpected identifier at ..." error at the first 'db.tags.remove...'.

...
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");
};
...

Any help would be most welcome,

Thanks,

Greg.


Solution

  • Misplaced " - took me a while to see it!

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

    Change it to "day" :