2017-05-25 99 views
0

在我angular2的项目,我需要更新多个ID与相同data.I有这样的功能:

import { AgentApi } from '../../../../sdk/services/custom/Agent'; 
@Injectable() 
export class AgentService { 
    constructor(private agentApi: AgentApi) { } 
    updateAgentShiftDetails(idArray, name) { 
    var dataObj: any = {}; 
    dataObj.id = { 
     'inq': idArray ------> id array contains ids like this:["590b095a0d271a0cb8e859sf", "590c63cee3adb75a19e84e56"] 
    }; 
    return this.agentApi.updateAll({ 
     where: { 
      'id': dataObj 
     } 
    }, { 
      'name': name 
     }); 
}; 
    } 
我responsebody

我得到了一个错误,如这样的:?

Object {statusCode: 500, name: "MongoError", message: "unknown operator: $id", ok: 0, errmsg: "unknown operator: $id"…} 
500 (Internal Server Error) 

我该如何解决这个问题我使用环回和mongodb.I是新来angular2任何帮助真的会明显

+0

它应该被_id? – Astro

+0

你的意思是:{ '_ id':dataObj }是这样的吗?但仍然是这个问题。 – Khushi

回答

0

对不起,我没有足够的信誉来添加。合作mment。 为什么你不使用$in这种情况?

this.agentApi.update({ _id: { $in: idArray } }, { name: name }, function (err, user) { 

}) 
+0

谢谢你的回答。我为我的问题找到了解决方案。没有哪里条款更新是这个问题。我解决了它。 agentApi.updateAll(dataObj,{' 'name':name });它工作正常参考:http://loopback.io/doc/en/lb2/Where-filter.html#where-clause-for-other-methods – Khushi

0

你应该避免使用其中这里

import { 
    AgentApi 
} from '../../../../sdk/services/custom/Agent'; 
@Injectable() 
export class AgentService { 
    constructor(private agentApi: AgentApi) {} 
    updateAgentShiftDetails(idArray, name) { 
     var dataObj: any = {}; 
     dataObj.id = { 
      'inq': idArray 
     }; 
     return this.agentApi.updateAll(dataObj, { 
      'name': name 
     }); 
    }; 
} 
+0

是的,我知道了我提到它的评论。谢谢。 – Khushi