[JAVA-2435] Abnormal query results! Created: 27/Jan/17  Updated: 27/Oct/23  Resolved: 27/Jan/17

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

Type: Task Priority: Major - P3
Reporter: Alireza Mohamadi [X] Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10 x64 JDK 1.8



 Description   

Hi.
This is the query I execute:

and(new Document("visits.userID", userID),new Document("orders.postReqID", postReqID)),
							new Document("$inc",
							             new Document("orders.$.viewCount", 1)
									             .append("orders.$.remaining", -1)
							)
									.append("$set", new Document("orders.$.endDate", currentTime)
											.append("visits.$.date", currentTime)),
							(r, t) ->
							{
								if (t != null)
								{
									t.fillInStackTrace();
									t.printStackTrace();
                                                                 }
                                                         });

And this produces:

com.mongodb.MongoCommandException: Command failed with error 11000: 'E11000 duplicate key error collection: ViewMember.posts index: orders.postReqID_1 dup key: { : null }' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "E11000 duplicate key error collection: ViewMember.posts index: orders.postReqID_1 dup key: { : null }", "code" : 11000, "codeName" : "DuplicateKey" }
	at com.sunova.bot.MongoDBDriver$14.lambda$requestAsync$1(MongoDBDriver.java:768)
	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
	at com.mongodb.async.client.MongoClientImpl$2$2.onResult(MongoClientImpl.java:144)
	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
	at com.mongodb.operation.OperationHelper$ReferenceCountedReleasingWrappedCallback.onResult(OperationHelper.java:368)
	at com.mongodb.operation.CommandOperationHelper$1.onResult(CommandOperationHelper.java:381)
	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
	at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor$1.onResult(DefaultServer.java:185)
	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
	at com.mongodb.connection.CommandProtocol$CommandResultCallback.callCallback(CommandProtocol.java:275)
	at com.mongodb.connection.ResponseCallback.onResult(ResponseCallback.java:48)
	at com.mongodb.connection.ResponseCallback.onResult(ResponseCallback.java:23)
	at com.mongodb.connection.DefaultConnectionPool$PooledConnection$2.onResult(DefaultConnectionPool.java:470)
	at com.mongodb.connection.DefaultConnectionPool$PooledConnection$2.onResult(DefaultConnectionPool.java:464)
	at com.mongodb.connection.UsageTrackingInternalConnection$3.onResult(UsageTrackingInternalConnection.java:119)
	at com.mongodb.connection.UsageTrackingInternalConnection$3.onResult(UsageTrackingInternalConnection.java:115)
	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
	at com.mongodb.connection.InternalStreamConnection.executeCallbackAndReceiveResponse(InternalStreamConnection.java:378)
	at com.mongodb.connection.InternalStreamConnection.access$1700(InternalStreamConnection.java:66)
	at com.mongodb.connection.InternalStreamConnection$ResponseBuffersCallback.onResult(InternalStreamConnection.java:420)
	at com.mongodb.connection.InternalStreamConnection$ResponseBuffersCallback.onResult(InternalStreamConnection.java:389)
	at com.mongodb.connection.InternalStreamConnection$ResponseHeaderCallback.onSuccess(InternalStreamConnection.java:562)
	at com.mongodb.connection.InternalStreamConnection$ResponseHeaderCallback.access$2200(InternalStreamConnection.java:517)
	at com.mongodb.connection.InternalStreamConnection$ResponseHeaderCallback$ResponseBodyCallback.onResult(InternalStreamConnection.java:584)
	at com.mongodb.connection.InternalStreamConnection$ResponseHeaderCallback$ResponseBodyCallback.onResult(InternalStreamConnection.java:568)
	at com.mongodb.connection.InternalStreamConnection$3.completed(InternalStreamConnection.java:447)
	at com.mongodb.connection.InternalStreamConnection$3.completed(InternalStreamConnection.java:444)
	at com.mongodb.connection.AsynchronousSocketChannelStream$BasicCompletionHandler.completed(AsynchronousSocketChannelStream.java:218)
	at com.mongodb.connection.AsynchronousSocketChannelStream$BasicCompletionHandler.completed(AsynchronousSocketChannelStream.java:201)
	at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:126)
	at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:281)
	at sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ReadTask.completed(WindowsAsynchronousSocketChannelImpl.java:579)
	at sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:397)
	at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

Well I put some null value in some orders.postReqID in order to diagnose why this happens. Seems query filter is being executed somehow!! Can you guide me why I encounter such a thing? It really confuses me



 Comments   
Comment by Ross Lawley [ 27/Jan/17 ]

Thanks SuNova - I'll check out the stackoverflow question and hopefully answer your question!

Comment by Alireza Mohamadi [X] [ 27/Jan/17 ]

Your attitude is one of most important reasons which encourages me to keep on using MongoDB. Thanks!
https://stackoverflow.com/questions/41897776/mongodb-query-filter-is-being-executed-as-update
And sorry if I didn't know this is not driver problem as I was thinking it is. Please kindly follow the link I pasted here. Regards

Comment by Ross Lawley [ 27/Jan/17 ]

Hi SuNova,

The error you are seeing is the response back from server, the Java driver is passing the findOneAndUpdate to the server and the server has returned the error message:

E11000 duplicate key error collection: ViewMember.posts index: orders.postReqID_1 dup key: { : null }

As far as I can tell this is not a Java driver bug or issue, so the best place for questions regarding MongoDB usage is the mongodb-user mailinglist or stackoverflow as you will reach a boarder audience there. If your business requires an answer from MongoDB within a time frame then we do offer production support.

I would suggest including some information on your MongoDB version and the Indexes on the collection - that may help shed some light on the issue. If you do follow up via one of the options above please post a link and I will follow the conversation there.

All the best,

Ross

Comment by Alireza Mohamadi [X] [ 27/Jan/17 ]

Sorry a part of code is not pasted. Apologizes. This is:

posts.findOneAndUpdate(
			and(new Document("visits.userID", userID),new Document("orders.postReqID", postReqID)),
			new Document("$inc",
						new Document("orders.$.viewCount", 1)
						.append("orders.$.remaining", -1)
							)
			.append("$set", new Document("orders.$.endDate", currentTime)
							.append("visits.$.date", currentTime)),
							(r, t) ->
							{
								if (t != null)
								{
									t.fillInStackTrace();
									t.printStackTrace();

Generated at Thu Feb 08 08:57:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.