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

MongoDB delete make changes only to first matched document #7809

Closed
2 of 21 tasks
SnapeEye opened this issue Jun 29, 2021 · 1 comment · Fixed by #7811
Closed
2 of 21 tasks

MongoDB delete make changes only to first matched document #7809

SnapeEye opened this issue Jun 29, 2021 · 1 comment · Fixed by #7811

Comments

@SnapeEye
Copy link
Contributor

Issue Description

Hello!
Got some problems when I need to delete data in MongoDB (working in NestJS). I have my Repository class, there I call delete method, pass all necessary params. But when operation is done, only one entity is deleted.

Expected Behavior

It is expected all entities, which were matched to my search params, to be deleted

Actual Behavior

For now, only the first entity, matching the search params, is deleted.

Steps to Reproduce

  1. Create 1-2 entity with name 'Test'
  2. Create 1 entity with name 'Original'
  3. Delete all entities with name 'Test'
@Entity('test')
export class TestEntity {
  @ObjectIdColumn()
  _id: string;

  @PrimaryColumn()
  id: string;

  @Column()
  name: string;
}

@EntityRepository(TestEntity)
export class TestRepository extends Repository<TestEntity> {
  async reproduce(): Promise<void> {
    await this.save({
      id: '1',
      name: 'Test',
    });
    await this.save({
      id: '2',
      name: 'Test',
    });
    await this.save({
      id: '3',
      name: 'Original',
    });
    await this.save({
      id: '4',
      name: 'Test',
    });
    console.log('Before delete call:');
    console.log(await this.find());
    await this.delete({ name: 'Test' });
    console.log('After delete call:');
    console.log(await this.find());
  }
}

My Environment

Dependency Version
Operating System Windows 10 Enterprise
Node.js version v14.17.0
Typescript version v4.3.2
TypeORM version v0.2.34

Relevant Database Driver(s)

  • aurora-data-api
  • aurora-data-api-pg
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time, and I know how to start.
  • Yes, I have the time, but I don't know how to start. I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
@SnapeEye
Copy link
Contributor Author

Issue is related to this one:
#7788

That issue fixed update operation. Here will be fixed delete operation.

SnapeEye added a commit to SnapeEye/typeorm that referenced this issue Jun 29, 2021
Delete operation should remove all matched documents, but now it removes the first found document

Closes: typeorm#7809
imnotjames pushed a commit that referenced this issue Jun 29, 2021
Delete operation should remove all matched documents, but now it removes the first found document

Closes: #7809
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants