Ошибка машинописи в операторах запроса на обновление Mongodb - PullRequest
0 голосов
/ 17 апреля 2020

Я новичок в Mongodb и получаю ошибку машинописи, когда пытаюсь поместить массив sh объектов в mongodb, используя метод pu sh. Для этого я использую сервис-оболочку mongdb.

public saveRental = () => {
    return this.connector
      .connect()
      .then(() => {
        return this.connector.update(
          "polcyData", // collection name
          { _id: "dummyid" },
          { "$push": { "myArray": { "field1": "abc", "field2": "def" } } },
        );
      });
};

Это ошибка, которую я получаю при наведении курсора $ pu sh метод:

(property) $push?: PushOperator<any> | undefined
Type '{ myArray: { field1: string; field2: string; }; }' is not assignable to type 'PushOperator<any>'.
  Type '{ myArray: { field1: string; field2: string; }; }' is not assignable to type 'NotAcceptedFields<any, any[]>'.
    Property 'myArray' is incompatible with index signature.
      Type '{ field1: string; field2: string; }' is not assignable to type 'undefined'.ts(2322)
index.d.ts(1256, 5): The expected type comes from property '$push' which is declared here on type 'UpdateQuery<any>'

Это параметры метода обновления:

update(collectionName: string, filter: MongoClient.FilterQuery<any>, update: MongoClient.UpdateQuery<any>, options?: MongoClient.UpdateOneOptions): Promise<any>;

Это тип UpdateQuery

/** https://docs.mongodb.com/manual/reference/operator/update */
export type UpdateQuery<TSchema> = {
    /** https://docs.mongodb.com/manual/reference/operator/update-field/ */
    $currentDate?: OnlyFieldsOfType<TSchema, Date, true | { $type: 'date' | 'timestamp' }>;
    $inc?: OnlyFieldsOfType<TSchema, number>;
    $min?: MatchKeysAndValues<TSchema>;
    $max?: MatchKeysAndValues<TSchema>;
    $mul?: OnlyFieldsOfType<TSchema, number>;
    $rename?: { [key: string]: string };
    $set?: MatchKeysAndValues<TSchema>;
    $setOnInsert?: MatchKeysAndValues<TSchema>;
    $unset?: OnlyFieldsOfType<TSchema, any, ''>;

    /** https://docs.mongodb.com/manual/reference/operator/update-array/ */
    $addToSet?: SetFields<TSchema>;
    $pop?: OnlyFieldsOfType<TSchema, any[], 1 | -1>;
    $pull?: PullOperator<TSchema>;
    $push?: PushOperator<TSchema>;
    $pullAll?: PullAllOperator<TSchema>;

    /** https://docs.mongodb.com/manual/reference/operator/update-bitwise/ */
    $bit?: {
        [key: string]: { [key in 'and' | 'or' | 'xor']?: number };
    };
};

Кто-нибудь может мне помочь с этим? Любая помощь могла бы быть полезна. Ошибка возникает только для операторов массива обновления: https://docs.mongodb.com/manual/reference/operator/update-array

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...