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

ObjectID string interface #598

Closed
7 tasks
hacksparrow opened this issue Sep 21, 2020 · 6 comments
Closed
7 tasks

ObjectID string interface #598

hacksparrow opened this issue Sep 21, 2020 · 6 comments

Comments

@hacksparrow
Copy link
Contributor

hacksparrow commented Sep 21, 2020

Follow up of loopbackio/loopback-next#3456.

All model properties defined as {type: String, mongodb: {dataType: 'objectID'} should be stored as ObjectID in the database but provide a string interface in the connector APIs. Meaning, string version of the ObjectID will be used in queries and results, ObjectID will not be directly exposed to users.

Any property not defined as {type: String, mongodb: {dataType: 'objectID'} will no be stored as ObjectID, even if the string looks like an ObjectID.

Acceptance criteria

  • Add implementation for String to ObjectID conversion in queries
  • Add implementation for ObjectID to String conversion in results
  • Refactor existing implementation wherever applicable
  • Remove redundant code
  • Update docs
  • Add tests
  • Add a "Long Term Support" section to README (see strongloop/loopback for inspiration) and also explain which connector versions are compatible with which LoopBack versions.
@dhmlau dhmlau added this to the Oct 2020 milestone Sep 23, 2020
@bajtos
Copy link
Member

bajtos commented Sep 25, 2020

Important: we already have a similar implementation in place for Decimal128 type. Going forward, we should have a single unified solution for dealing with string-based data-types (ObjectID, Decimal128), to ensure consistent handling of edge cases like nested properties in anonymous models, nested array items, etc.

@hacksparrow
Copy link
Contributor Author

Yes, in the proposed approach ObjectID and Decimal128 coercion happen in the same block. It can be further optimized.

@mikeevstropov
Copy link

mikeevstropov commented Jun 12, 2021

@hacksparrow When you said
Any property not defined as {type: String, mongodb: {dataType: 'objectID'} will no be stored as ObjectID, even if the string looks like an ObjectID.
Will the CLI automatically set dataType for relation? It looks like i need to handle it manually each time when i generate the relation via lb4 relation. 😯

@stale
Copy link

stale bot commented Aug 11, 2021

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 stale label Aug 11, 2021
@stale
Copy link

stale bot commented Aug 25, 2021

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this as completed Aug 25, 2021
@paviln
Copy link

paviln commented Dec 21, 2021

Hello,

When I use find on a repo, which model has a belongsTo:

// Foreign key
@belongsTo(
() => User,
{}, //relation metadata goes in here
{
// property definition goes in here
type: 'string',
required: true,
mongodb: {dataType: 'ObjectId'},
},
)
userId: string;

The result userId type is a object and not a string. This is annoying, since I want to use where neq..

The userId is stroed as ObjectId, if i change it to a string, I get a string value. But it should provide it as a string, even if it is a objectId?

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

5 participants