-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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 update make changes only to first matched document #7788
Comments
Got the fix solution, but unable to push branch with changes... |
Please feel free to try to get the changes up in a PR or post the diff here. |
I've read all the roadmap of contribution, made changes and tests but was unable to push branch with changes. Got 2 different commands to try:
But, anyway, here is the diff (MongoEntityManager.ts). Maybe you can help with adding it. async update<Entity>(target: EntityTarget<Entity>, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | FindConditions<Entity>, partialEntity: QueryDeepPartialEntity<Entity>): Promise<UpdateResult> {
if (Array.isArray(criteria)) {
await Promise.all((criteria as any[]).map(criteriaItem => {
return this.update(target, criteriaItem, partialEntity);
}));
} else {
const metadata = this.connection.getMetadata(target);
- await this.updateOne(target, this.convertMixedCriteria(metadata, criteria), { $set: partialEntity });
+ await this.updateMany(target, this.convertMixedCriteria(metadata, criteria), { $set: partialEntity });
}
return new UpdateResult();
} |
Looks like you need to fork the repo - you're trying to push directly to |
Update operation should update all matched documents, but now it updates the first found document Closes: typeorm#7788
mongo update operation should update all matched documents, but now it updates the first found document fixes #7788
Issue Description
Hello!
Got some problems when I need to update data in MongoDB (working in NestJS). I have my Repository class, there I call update method, pass all necessary params. But when operation is done, only one entity is updated.
Expected Behavior
It is expected all entities, which were matched to my search params, to be updated
Actual Behavior
For now, only the first entity, matching the search params, is updated.
Steps to Reproduce
Logs:
My Environment
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: