You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When I perform a bulk write operation (inserting or saving a list) when the list contains duplicates that are already in the database (with a unique index on several attributes of this class), the elements of the list before the duplicate are inserted but not those after.
I've thought about a workaround but this inevitably leads to data loss, especially as it's impossible to know which elements have been inserted and which haven't since insert or save systematically returns the same list as was sent.
For example, I tried to insert (or save) at first, I catch the BulkWriteError, parse the message to identify which data hasn't been inserted, filter it on the original array and try once again to insert. But with this method, the elements before the duplicates has been inserted and at the second time, became a duplicate too.
I tested the performance of looping on the array and insert one by one the data but this 5 time slower on an array of 10k elements.
To Reproduce
Steps to reproduce the behavior:
Have a model with multiple attributes like name, category etc
Create a unique index on these attributes
Insert a data
Try to save / insert a list containing the data already in the database, you can try at different positions in the list.
Expected behavior
Mutiple choice here, assuming there is a unique index on the table :
log the E11000 duplicate key error collection but continues to insert the other elements of the array, returns a list of elements that cannot be inserted or those that have been inserted
or returns the list of the elements that cannot be inserted (that means duplicates and those after the duplicates) in order to retry.
something else?
** Please complete the following information: **
Server Version: mongo 7.0.5
Driver Version: mongodb-driver-sync:4.11.1
Morphia Version: morphia-core:2.4.11
Additional context
Model
@Entity("tmPackets")
@Indexes({@Index(fields = @Field(value = "receptionTime", type = IndexType.DESC)),
@Index(fields = @Field(value = "onBoardTime", type = IndexType.DESC)),
@Index(fields = @Field(value = "packetType", type = IndexType.DESC)),
@Index(
fields = {@Field(value = "onBoardTime", type = IndexType.DESC),
@Field(value = "sourceSeqCount", type = IndexType.DESC),
@Field(value = "apid", type = IndexType.DESC)},
options = @IndexOptions(unique = true))})
publicclassTmPacketToStore {
/** * ID of the packet. This field is only used after storing. */@Id@JsonSerialize(using = ObjectIdSerializer.class)
@JsonDeserialize(using = ObjectIdDeserializer.class)
privateObjectIdid;
/** * Raw binary values of the packet. */privatebyte[] rawPacket;
/** * The ground reception time. */privateInstantreceptionTime;
/** * The onboard time. */privateInstantonBoardTime;
/** * The type of the packet. */privateStringpacketType;
/** * The APID of the packet. */privatelongapid;
/** * The source sequence counter. */privatelongsourceSeqCount;
Describe the bug
When I perform a bulk write operation (inserting or saving a list) when the list contains duplicates that are already in the database (with a unique index on several attributes of this class), the elements of the list before the duplicate are inserted but not those after.
I've thought about a workaround but this inevitably leads to data loss, especially as it's impossible to know which elements have been inserted and which haven't since insert or save systematically returns the same list as was sent.
For example, I tried to insert (or save) at first, I catch the BulkWriteError, parse the message to identify which data hasn't been inserted, filter it on the original array and try once again to insert. But with this method, the elements before the duplicates has been inserted and at the second time, became a duplicate too.
I tested the performance of looping on the array and insert one by one the data but this 5 time slower on an array of 10k elements.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Mutiple choice here, assuming there is a unique index on the table :
E11000 duplicate key error collection
but continues to insert the other elements of the array, returns a list of elements that cannot be inserted or those that have been inserted** Please complete the following information: **
Additional context
Model
DAO
Test
The text was updated successfully, but these errors were encountered: