[JAVA-3784] Array List order not maintained sometimes Created: 10/Jul/20  Updated: 27/Jul/20  Resolved: 27/Jul/20

Status: Closed
Project: Java Driver
Component/s: Test Failure
Affects Version/s: 3.4.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Astha Gupta Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Regarding handling lists in Mongo using the Java driver (3.2.2) and mongo db version 3.4
 
We have been creating a list of strings as follows and storing them in Mongo:

Document result = new Document();
result.put("_id", i);
 
List<String> list = new ArrayList<>();
list.add("john");
list.add("jack");
result.put("listName", list);
testCollection.insertOne(result);

 
But, my colleague was testing some code and noticed that the order in one of the items in the list after retrieval from mongo was different than the order that was inserted, but we haven't been able to replicate the issue again.
 
Is the way we are handling this the right way to do it or do you suggest that we also insert the list order along with the objects?
 



 Comments   
Comment by Esha Bhargava [ 27/Jul/20 ]

asthagupta92@gmail.com Thanks for your report! Please note that this project is for reporting bugs or feature suggestions for the driver. For MongoDB-related support discussion please post on the MongoDB Community Forums. A question like this involving more discussion would be best posted on the MongoDB community.

Comment by Jeffrey Yemin [ 10/Jul/20 ]

The Java code looks fine. Is it possible that the document is also being updated after insertion, and the update is responsible for the re-ordering?

Generated at Thu Feb 08 09:00:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.