0

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.

Khushi
  • 1,759
  • 6
  • 26
  • 45

2 Answers2

2

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
        });
    };
}
KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133
0

Sorry, I don't have enough reputation to add a comment. Why don't you use $infor this case?

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

} )
Toan Tran
  • 1,937
  • 1
  • 24
  • 37
  • Thank you for your answer. I found solution for my issue. there is no where clause for updateall that was the problem. I solved it. agentApi.updateAll(dataObj, { 'name': name }); it works correctly reference: http://loopback.io/doc/en/lb2/Where-filter.html#where-clause-for-other-methods – Khushi May 25 '17 at 08:31