[JAVA-4549] Some Document Can Not Be Found By Mongo Java Client Created: 25/Mar/22  Updated: 27/Oct/23  Resolved: 28/Mar/22

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

Type: Bug Priority: Unknown
Reporter: 仲鲍 杨 Assignee: Ross Lawley
Resolution: Works as Designed Votes: 0
Labels: external-user
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Summary

Some Document Can Not Be Found By Mongo Java Clinet。

client version:4.5.1

server version: 4.2.5

Java Code:

```
long l = database.getCollection("currency_log").countDocuments( Filters.and( Filters.gte("time", 1647792000), Filters.lt("time", 1647878400) ) );
```

return count is :588177

Query Ql In Tool:NoSQLBooster for MongoDB

```
db.currency_log.find({time:{"$gte":1647792000,"$lt":1647878400}}).count()
```

return count is :588178

 

Then I Find The Lose Document is 

```
db.currency_log.find({_id:ObjectId("62388633f12eb410f0e6d922")})
```

The I just find Document By ObjectId By Java Mongo Driver , But Still Not Find Id;

Java Code is below

```
long count = database.getCollection("currency_log").countDocuments(Filters.eq("_id", new ObjectId("62388633f12eb410f0e6d922")));
```

 

 



 Comments   
Comment by Ross Lawley [ 28/Mar/22 ]

Hi onemail1876@gmail.com,

Glad you found the cause of the issue! Closing this ticket.

All the best,

Ross

Comment by 仲鲍 杨 [ 28/Mar/22 ]

I'm so sorry that it a Oolong!

the java dirver connect mongodb is an backup mongodb,but NoSQLBooster connect's Mongo is a Productive MongoDB.....

when i change java driver mongo db the count is then same between NoSQLBooster and mongo java dirver

Comment by 仲鲍 杨 [ 28/Mar/22 ]

I'm so Soryy ,that i can not provide you a minimal reproducible example now.

but i find that go mongo driver can find a real count.

Comment by Ross Lawley [ 25/Mar/22 ]

Hi onemail1876@gmail.com,

Thanks - checking out "NoSQLBooster" it uses the node driver underneath - so I wouldn't expect to find any differences in the results between that and the shell, the java driver and pymongo. As they all follow the same specifications and run the specification test suite.

One thing to note is the example document has _id as a string value and not an ObjectId - so that is something I would double check. eg:

 database.getCollection("currency_log").find(Filters.eq("_id", new ObjectId("62388633f12eb410f0e6d922"))).first();
 database.getCollection("currency_log").find(Filters.eq("_id", "62388633f12eb410f0e6d922")).first();

When testing locally on MongoDB 4.2 using the shell I didn't see any issues:

MongoDB Enterprise > db.test.insertOne({ "_id": "62388633f12eb410f0e6d922", "account_id": 1041152, "amount_after": 2547356, "currency_type": 3, "delta": 150, "description": "", "io": 2, "reason": 0, "role_id": 4552713003, "role_level": 2711, "role_name": "ToXicYBLYUDOK", "role_type": 2823000001, "server": 3006, "sex": 2802000019, "stime": "20220321.220539", "time": 1647871539, "urs": "121025659" })
{ "acknowledged" : true, "insertedId" : "62388633f12eb410f0e6d922" }
MongoDB Enterprise > db.test.findOne({time:{"$gte":1647792000,"$lt":1647878400}})
{
	"_id" : "62388633f12eb410f0e6d922",
	"account_id" : 1041152,
	"amount_after" : 2547356,
	"currency_type" : 3,
	"delta" : 150,
	"description" : "",
	"io" : 2,
	"reason" : 0,
	"role_id" : 4552713003,
	"role_level" : 2711,
	"role_name" : "ToXicYBLYUDOK",
	"role_type" : 2823000001,
	"server" : 3006,
	"sex" : 2802000019,
	"stime" : "20220321.220539",
	"time" : 1647871539,
	"urs" : "121025659"
}
 
MongoDB Enterprise > db.test.findOne({_id: ObjectId("62388633f12eb410f0e6d922")})
null
MongoDB Enterprise > db.test.findOne({_id: "62388633f12eb410f0e6d922"})
{
	"_id" : "62388633f12eb410f0e6d922",
	"account_id" : 1041152,
	"amount_after" : 2547356,
	"currency_type" : 3,
	"delta" : 150,
	"description" : "",
	"io" : 2,
	"reason" : 0,
	"role_id" : 4552713003,
	"role_level" : 2711,
	"role_name" : "ToXicYBLYUDOK",
	"role_type" : 2823000001,
	"server" : 3006,
	"sex" : 2802000019,
	"stime" : "20220321.220539",
	"time" : 1647871539,
	"urs" : "121025659"
}

I think to take this further I'd need to be able to reproduce the issue. Ideally, I'd ask for a minimal reproducible example as that would help as I could then replicate the issue and potentially use it to find if there is a bug.

All the best,

Ross

Comment by 仲鲍 杨 [ 25/Mar/22 ]
{ "_id": "62388633f12eb410f0e6d922", "account_id": 1041152, "amount_after": 2547356, "currency_type": 3, "delta": 150, "description": "", "io": 2, "reason": 0, "role_id": 4552713003, "role_level": 2711, "role_name": "ToXicYBLYUDOK", "role_type": 2823000001, "server": 3006, "sex": 2802000019, "stime": "20220321.220539", "time": 1647871539, "urs": "121025659" }
Comment by 仲鲍 杨 [ 25/Mar/22 ]

I have export the some collectiion from mongo by mongoexport then load them to an analysis system.

after finish the process of data load.

i write a code support by java mongo dirver to check the data between mongo and analysis system.then find some data count is diff.

 

Comment by Ross Lawley [ 25/Mar/22 ]

Hi onemail1876@gmail.com,

Can you output the full document ?

Many thinks,

Ross

Comment by 仲鲍 杨 [ 25/Mar/22 ]

I have try mongo shell、mongo java driver、pymongo,all of them can not find the document who's ObjectId is 62388633f12eb410f0e6d922,Only NoSQLBooster for MongoDB can find this document

Comment by Ross Lawley [ 25/Mar/22 ]

Thanks onemail1876@gmail.com,

So only "NoSQLBooster for MongoDB" returns a different count?

I could possibly understand a difference in the count value - as countDocuments uses the aggregation framework for the count. See the documentation on count where as the legacy count method used the temporary metadata to provide results - but I wouldn't expect that to be the case using a standalone mongodb. countDocuments was added in JAVA-2885.

Can you confirm that "NoSQLBooster for MongoDB" can find the document with the ObjectId("62388633f12eb410f0e6d922"), where as all other drivers / the shell cannot?
This I don't understand, as the shell and the drivers just query MongoDB and get the results back and I imagine the same goes for NoSQLBooster. Is there anything different / unusual about that document? Could it be related to NoSQLBooster itself (eg a temporary document)?

Other things to be aware of are the latest version of MongoDB is 5.0.6 and the latest MongoDB 4.2 version is 4.2.19 - I don't think that is related but its more for your information.

Many thanks,

Ross

Comment by 仲鲍 杨 [ 25/Mar/22 ]

The Result Of Mongo Shell is the same with mongo java dirver.The I use pymongo get the same result with mongo java driver.

the toplogy of the mongo db is standalone mongodb

Comment by Ross Lawley [ 25/Mar/22 ]

Hi onemail1876@gmail.com,

Thank you for the ticket. In order to understand the cause more, can I ask you to confirm the count using the mongo shell?

Secondly, can you provide more information on the toplogy you are using eg: standalone mongodb, replicaset, sharded cluster, sharded replicaset cluster.

Many thanks,

Ross

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