0

在我的 angular2 项目中,我需要使用相同的数据更新多个 id。我有一个这样的函数:

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

在我的响应正文中,我收到了这样的错误:

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

我该如何解决这个问题?我正在使用环回和 mongodb。我是 angular2 的新手。任何帮助都会非常显着。

4

2 回答 2

1

你应该避免使用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
        });
    };
}
于 2017-05-25T08:48:29.297 回答
0

抱歉,我没有足够的声望来添加评论。你为什么不用$in这个案子呢?

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

} )
于 2017-05-25T07:36:35.660 回答