Reputation: 1859
In my angular2 project i need to update multiple ids with same data.I have a function like this:
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
});
};
}
in my responsebody i got an error like this:
Object {statusCode: 500, name: "MongoError", message: "unknown operator: $id", ok: 0, errmsg: "unknown operator: $id"…}
500 (Internal Server Error)
How can i resolve this problem? am using loopback and mongodb.I am new to angular2. Any help will really appreciable.
Upvotes: 0
Views: 2076
Reputation: 20098
You should avoid use of where here
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
});
};
}
Upvotes: 2
Reputation: 2047
Sorry, I don't have enough reputation to add a comment.
Why don't you use $in
for this case?
this.agentApi.update( { _id: { $in: idArray } }, { name: name }, function (err, user) {
} )
Upvotes: 0