Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model.bulkWrite updateOne.update and updateMany.update type UpdateFilter<TSchema> should be compatible with Model.updateOne and Model.updateMany type UpdateQuery<T> #12595

Closed
2 tasks done
ahmedelshenawy25 opened this issue Oct 25, 2022 · 0 comments · Fixed by #12742
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@ahmedelshenawy25
Copy link
Contributor

ahmedelshenawy25 commented Oct 25, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

6.7.0

Node.js version

16.17.0

MongoDB server version

5.0.5

Typescript version (if applicable)

4.8.4

Description

same issue as #11911

Steps to Reproduce

import mongoose, { UpdateQuery } from 'mongoose';
const { Schema, model } = mongoose;

async function run() {
  await mongoose.connect('mongodb://localhost:27017/test');

  interface IAnimal {
    name?: string;
  }

  const animalSchema = new Schema<IAnimal>({
    name: { type: String }
  });

  const Animal = model<IAnimal>('Animal', animalSchema);

  const writeOperations = ['foo', 'bar', 'baz'].map(name => {
    const changes: UpdateQuery<IAnimal> = {}

    if (name === 'foo') {
      changes.name = name.repeat(2);
    } else {
      changes.name = name.repeat(4);
    }

    return {
      updateOne: {
        filter: { name },
        update: changes
      }
    }
  })

  await Animal.bulkWrite(writeOperations);
}
run();
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "skipLibCheck": true,
  }
}

Expected Behavior

Model.bulkWrite (updateOne.update || updateMany.update) UpdateFilter and Model.updateOne UpdateQuery should be compatible

@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Nov 1, 2022
@vkarpov15 vkarpov15 added this to the 6.7.4 milestone Nov 1, 2022
vkarpov15 added a commit that referenced this issue Nov 25, 2022
@vkarpov15 vkarpov15 modified the milestones: 6.7.4, 6.7.5 Nov 28, 2022
vkarpov15 added a commit that referenced this issue Nov 30, 2022
fix(types): support using `UpdateQuery` in `bulkWrite()`
vkarpov15 added a commit that referenced this issue Dec 4, 2022
feat(schema+types): add `{ errorHandler: true }` option to Schema `post()` for better TypeScript support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants