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

Soft deleted docs still being pulled in Mongodb #7113

Closed
2 of 21 tasks
mak-pun opened this issue Nov 26, 2020 · 1 comment · Fixed by #8581
Closed
2 of 21 tasks

Soft deleted docs still being pulled in Mongodb #7113

mak-pun opened this issue Nov 26, 2020 · 1 comment · Fixed by #8581

Comments

@mak-pun
Copy link

mak-pun commented Nov 26, 2020

Expected Behavior

As described in the document TypeORM will only pull "non-deleted" entities from the database.

Actual Behavior

TypeORM still pulls "non-deleted" entities from the database.

This is the output from findAllConfigurations method.

[
    {
        "_id": "5fbfdf1388c68eaa23ff0d40",
        "createdAt": "2020-11-26T17:00:03.111Z",
        "updatedAt": "2020-11-26T17:00:40.637Z",
        "deletedAt": "2020-11-26T17:00:40.637Z",
        "exchange": {
            "className": "KuCoin",
            "sandboxMode": false,
            "id": "kucoin",
            "symbol": "ADA/USDT",
            "credentials": {
                "apiKey": "ddd",
                "secret": "abc"
            }
        },
        "bot": {
            "name": "test5",
            "className": "SmartGridBot",
            "extraSettings": {
                "startZone": 1,
                "endZone": 111,
                "initialCapital": 111,
                "numberOfZones": 111
            }
        }
    }
]

Steps to Reproduce

  1. Add a document. The document will have a deletedAt field with a value of null.
  2. Delete document with softRemove.
  3. Fetch the collection the document deleted still shows up.
// Repositiory

@EntityRepository(Configuration)
export class ConfigurationRepository extends MongoRepository<Configuration> {

  async findAllConfigurations(): Promise<Configuration[]> {
    const configurations = await this.find()
    return configurations
  }

  async deleteConfiguration(
    configuration: Configuration
  ): Promise<ObjectID> {
    await this.softRemove(configuration)
    return configuration._id
  }
}

// Entity

@Entity()
export class Configuration extends BaseEntity {
  @ObjectIdColumn()
  _id: ObjectID;

  @Column(type => Exchange)
  exchange: Exchange;

  @Column(type => Bot)
  bot: Bot;

  @VersionColumn()
  __v?: number

  @CreateDateColumn()
  createdAt?: Date

  @UpdateDateColumn()
  updatedAt?: Date

  @DeleteDateColumn()
  deletedAt?: Date
}

My Environment

| Dependency | Version |
Operating System macOS Mojave Version 10.14.6
Node.js version v14.15.1
Typescript version
├─┬ @nestjs/cli@7.5.3
│ └── typescript@4.0.5
└── typescript@4.1.2
TypeORM version
└── typeorm@0.2.29

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.
@arnabrahman
Copy link

arnabrahman commented Jan 28, 2022

This is still open. Any update?

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.

3 participants