-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fix: add support for mongodb driver v5 #9778
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
fix: add support for mongodb driver v5 #9778
Conversation
e11398f to
b88d8d9
Compare
d6c1768 to
9e75423
Compare
|
Hi, are there any updates on this or is there something i could help out with? Would love to get support for the new driver soon 😃 |
Hi, I would like some help, thanks. We need to find how force mongo to stop create the _id field when collection is created, because mongo is always creating now this field : https://www.mongodb.com/docs/manual/core/document/#the-_id-field So, if there is a entity with an other id name field the mongo will create _id field, like this example: The result is: |
|
Hi, i looked through the code and it seems like this behaviour is related to this issue: #9727 The additional
Entity from DB: ![]() Subject Entity to persist:
Because it has no id the following happens:
typeorm/src/persistence/SubjectExecutor.ts Lines 134 to 148 in 58fc088
typeorm/src/persistence/Subject.ts Lines 182 to 200 in 58fc088
I think the fix would be to check for the ...
// handle _id property the special way
if (metadata.objectIdColumn) {
const { databaseNameWithoutPrefixes, propertyName } =
metadata.objectIdColumn
const documentIdWithoutPrefixes =
document[databaseNameWithoutPrefixes]
const documentIdWithPropertyName = document[propertyName]
if (documentIdWithoutPrefixes) {
entity[propertyName] = documentIdWithoutPrefixes
hasData = true
} else if (documentIdWithPropertyName) {
entity[propertyName] = documentIdWithPropertyName
hasData = true
}
}
...This now adds the id from the document to the entity and results in an update to the same entity instead of an insert. |
|
Thank you for your help dude! |
d211e9e to
22b150d
Compare
|
@pleerock There is an error Oracle test, but we didn't any changes on Oracle source |
|
@pleerock I would like to update the typings, so everyone can now use the official typings already included in the As far i can see, i cannot use
These all just need the type of the ObjectId. Mongo specific files like MongoEntityManager already import from mongodb, so I guess they are ok. |
| ObjectId, | ||
| MongoError, | ||
| FilterOperators, | ||
| } from "mongodb" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't have direct imports from mongodb
No, we must not have imports from |
This new fix allow support to mongodb driver v5 Closes: typeorm#7907
This new fix allow support to mongodb driver v5 Closes: typeorm#7907
Instanceof check now no longer references to just the type but the loaded class ref instead.
22b150d to
115059d
Compare
This new fix allow support to mongodb driver v5 Closes: typeorm#7907
a7217b0 to
2504a53
Compare
This new fix allow support to mongodb driver v5 Closes: typeorm#7907
|
@MatheusMeloAntiquera how about not submitting the same changes in separate PRs? |
9d38119 to
cf9d7a5
Compare
I will keep this PR, sorry for copy your code I wanted to resolve this quickly, but you should have create a PR to my branch, not directly to typeorm repository |
cf9d7a5 to
07186d0
Compare




This new fix allow support to mongodb driver v5
Closes: #7907
Description of change
Add support for mongodb v5.0.1
mapReducewas removed because is deprecated since 5.0, instead should use an aggregation pipeline(https://www.mongodb.com/docs/manual/reference/method/db.collection.mapReduce/)
Pull-Request Checklist
masterbranchnpm run formatto apply prettier formattingnpm run testpasses with this changeFixes #0000