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

Schema with _id: false still has id #746

Closed
royibernthal opened this issue Jan 26, 2020 · 7 comments
Closed

Schema with _id: false still has id #746

royibernthal opened this issue Jan 26, 2020 · 7 comments
Assignees
Milestone

Comments

@royibernthal
Copy link

royibernthal commented Jan 26, 2020

I'm using tsed 5.34.0.

I have a model which contains a schema.
I specified { schemaOptions: { _id: false } } in the Schema decorator, so the schema shouldn't have an id.
However, I'm still seeing an _id field inside the sub-document in the database.

Any idea why?

To be fair, I'm not even sure where I got schemaOptions from, I can't find it anywhere in the docs now. Is it perhaps an obsolete way to do it?

@Schema({ schemaOptions: { _id: false } })
export default class MySchema {

  @Property()
  some_property: string;

}

@Model()
export default class ModelWithSchema {

  @ObjectID('id')
  _id: string;

  @Property()
  my_schema: MySchema;

}
@Romakita
Copy link
Collaborator

Hello @royibernthal

I checked the code and I don't know where come from the problem. The options is correctly given to the Schema constructor. Maybe it's the id param the problem. I'll continue to investigate.

@Romakita Romakita added this to the BACKLOG milestone Jan 31, 2020
@royibernthal
Copy link
Author

Hey @Romakita

Okay thanks. For what it's worth, it used to work a while ago.

@Romakita
Copy link
Collaborator

Damned.... I’ll check the commits xD

@royibernthal
Copy link
Author

Sounds like the way to go :) Were you able to repro?

@Romakita
Copy link
Collaborator

Romakita commented Feb 2, 2020

Hello @royibernthal
I tried to reproduce your issue without success.
Here a PR where I added some unit test to be sure that the schemaOptions is correctly given the the Schema.

#752

You'll see the unit test confirm that is work as expected.
You can copy the unit test and test your model with your actual implementation. Maybe something is different in your side.

See you

@royibernthal
Copy link
Author

royibernthal commented Feb 8, 2020

Hey @Romakita

Sorry for the late reply.

I tested this, admittedly not via a unit test, I just logged the schema's options.

I have 4 schemas that specify @Schema({ schemaOptions: { _id: false } }) in exactly the same way.

3 out of those have the problem, while 1 somehow doesn't.

Those 3 problematic schemas are nested inside a different model than the 1 schema that works as expected - it might be a clue to what's going on.

The problem can be seen both in the database and _id property in the logged schema options (which I assume is the heart of your unit test).

Just to make sure everything is clear:

3 schemas - have _id: true in their logged schema options, as well as have the _id field in the database.

1 schema - has _id: false in its logged schema options, as well as doesn't have the _id field in the database.

@stale
Copy link

stale bot commented Oct 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Oct 9, 2020
@stale stale bot closed this as completed Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants