Replies: 2 comments
-
Give many thanks to this author of awesome lib.
await this.em.insertMany(
City,
mongoCities.map((city) => this.em.create(City, city as any))
);
mongoCities.forEach((city) => {
const _city = this.em.create(City, city as any);
this.em.persist(_city);
});
await this.em.flush(); |
Beta Was this translation helpful? Give feedback.
-
This is not reproducible, sounds like you are using different EM forks (= different contexts), and auto-flush gets triggered by the Note that you are not using the method correctly, this is how it's supposed to be used: // no need to create entity instances yourseft
await this.em.insertMany(City, mongoCities);
// or create the instances and provide them in the first parameter
const entities = mongoCities.map((city) => this.em.create(City, city as any));
await this.em.insertMany(entities); Btw, you shouldn't need the The difference between Actually, yes, this is exactly what is happening to you, you are just mixing two approaches. This should help: 94eed5e?w=1 |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
I use insertMany to insert multiple record, but if I find right after insertMany, it cause duplicate key value violates unique constraint.
Code describe
Expected behavior
After insertMany, I can find without cause error !
Versions
Beta Was this translation helpful? Give feedback.
All reactions