update method

Future<DbUpdateResponse> update(
  1. Map<String, dynamic>? data
)

Implementation

Future<DbUpdateResponse> update(Map<String, dynamic>? data) async {
  if (data == null) {
    return DbUpdateResponse(
      code: CloudBaseExceptionCode.INVALID_PARAM,
      message: '参数必需是非空对象',
    );
  }

  if (data.containsKey('_id')) {
    return DbUpdateResponse(
      code: CloudBaseExceptionCode.INVALID_PARAM,
      message: '不能更新_id的值',
    );
  }

  Map<String, dynamic> params = {
    'query': this._fieldFilters,
    'muti': true,
    'merge': true,
    'upsert': false,
    'data': Serializer.encode(data),
    'interfaceCallSource': 'BATCH_UPDATE_DOC',
  };

  CloudBaseResponse res =
      await _queryRequest('database.updateDocument', params);
  if (res.code != null) {
    return DbUpdateResponse(
      code: res.code,
      message: res.message,
      requestId: res.requestId,
    );
  }

  return DbUpdateResponse(
    requestId: res.requestId,
    updateId: res.data['upserted_id'],
    updated: res.data['updated'],
  );
}