js的mongodb查询脚本。条件作为要迭代的数组

时间:2013-05-10 09:56:10

标签: javascript mongodb mongodb-query

    db = db.getSiblingDB("aqua") //same as use otherdb
    var legalStatus=["initiate","process","complete","replicating","failed","offline_complete","offline_fail","invalid"];
    var replicas=db.aquaObject.find({"replicas":{$ne:null},"replicas.status":{$nin:legalStatus}});
    replicas.forEach(
function(t){
    db.aquaObject.update(t,{$set:{"replicas.0.status":"initiate"}});
});

这是我写的脚本。但是find方法中的条件:"replicas.status",这里replicas是一个数组。我想迭代所有副本并过滤每个副本的状态。所以我相信我写的不正确。我该如何改进它?感谢。

0 个答案:

没有答案