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: When field is null in db, typeorm query sets it to undefined #7760
Mongodb: When field is null in db, typeorm query sets it to undefined #7760
Comments
@SnapeEye |
Actually I don't know any workaround. I've spent some time in typeorm code, researching this issue. Here what I can say:
I believe that if you store null or undefined value in your DB - its quite ok. As for now - I don't see any problems, conflicts in it. UPDATE: |
Expected diff with changes (DocumentToEntityTransformer.ts): transform(document: any, metadata: EntityMetadata) {
...
// get value from columns selections and put them into object
metadata.ownColumns.forEach(column => {
const valueInObject = document[column.databaseNameWithoutPrefixes];
- if (valueInObject !== undefined &&
- valueInObject !== null &&
- column.propertyName &&
+ if (column.propertyName &&
!column.isVirtual) {
// const value = this.driver.prepareHydratedValue(valueInObject, column);
entity[column.propertyName] = valueInObject;
hasData = true;
}
});
...
} |
I think it should still retain the strict undefined check, shouldn't it? |
I believe that it us very useful to get the whole entity model in response. And if some fields has undefined value, you can see it clearly and fix the issue (if it is required). As for now, I don't see any negative points in undefined values. Maybe you know any potential issues that may raise if undefined check will be removed? |
|
'undefined' value may be set in response if user didn't set in in db. You can see this example above on screenshots (field But if you suggest to keep this check - let's keep it. I think you should know better) |
…cuments Find operation should add all nullable values from documents if they exist Closes: typeorm#7760
Issue Description
When using TypeORM with MongoDB, you have the opportunity to set this decorator on a field:
When you query the collection, the returned documents that have a null value in the database, have the field value set to undefined.
Expected Behavior
The value of field in the queried documents should be set to null instead of undefined.
Actual Behavior
The value of field in the queried documents should is set to undefined instead of null.
Steps to Reproduce
nullableField
set tonull
:[{ nullableField: null, otherField: 1 }, { nullableField: null, otherField: 2 }]
undefined
will be printed instead of the expectednull
.My Environment
Additional Context
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?
The text was updated successfully, but these errors were encountered: