[SERVER-19907] Distinct command should accept a BSON element of type null for the "query" field Created: 12/Aug/15  Updated: 19/Sep/15  Resolved: 02/Sep/15

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.1.7
Fix Version/s: 3.1.8

Type: Bug Priority: Major - P3
Reporter: Craig Wilson Assignee: YunHe Wang
Resolution: Done Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CSHARP-1376 Distinct should not send a null value... Closed
is related to SERVER-15020 Implement explain for the distinct co... Closed
is related to SERVER-15456 relax validation of "query" field in ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

with 3.1.6, start a shell:

> db.runCommand({distinct: "bar", key: "x", query: null})
{
        "waitedMS" : NumberLong(0),
        "values" : [ ],
        "stats" : {
                "n" : 0,
                "nscanned" : 0,
                "nscannedObjects" : 0
        },
        "ok" : 1
}

with 3.1.7, start a shell:

> db.runCommand({distinct: "bar", key: "x", query: null})
{
        "waitedMS" : NumberLong(0),
        "ok" : 0,
        "errmsg" : "\"query\" had the wrong type. Expected Object, found NULL",
        "code" : 14
}

Sprint: Quint 9 09/18/15
Participants:

 Description   

The distinct command used to accept a null query parameter (up through 3.1.6), but the latest nightly (3.1.7) raises an error.

This will be a backwards breaking change for any user/driver that was sending a null query.



 Comments   
Comment by Githook User [ 02/Sep/15 ]

Author:

{u'name': u'Yunhe (John) Wang', u'email': u'yunhe.wang@mongodb.com'}

Message: SERVER-19907 Modified distinct to accept query=null and added jstest

Closes #1013

Signed-off-by: David Storch <david.storch@10gen.com>
Branch: master
https://github.com/mongodb/mongo/commit/529a9b0e9b9eecf770c9819da4cfcc6a0a5ddd05

Comment by J Rassi [ 12/Aug/15 ]

Thanks. The existence of an official driver with this behavior seems like a good enough reason to me to provide a backwards-compatibility fix for this issue, although I'd like to see the driver fixed as well.

Craig, can you please file a ticket to fix the .NET driver to omit the "query" field from the distinct command object if the user does not provide a query predicate, and link the ticket here?

Comment by Craig Wilson [ 12/Aug/15 ]

I know the .NET driver is failing some tests. They are all 1 specific path through the old LINQ provider, so any user with code like this will get the failure:

var results = collection.Select(x => x.B).Distinct();
 
// or
 
var results = (from x in collection
               select x.B).Distinct();

I don't know of any other drivers that would be doing this without user intervention as none other is translating queries like this. I also don't know how many others would actively prevent null from being sent intentionally when provided by a user.

Comment by J Rassi [ 12/Aug/15 ]

Craig, what existing drivers do you know of that will issue a distinct operation to the server with a null value for "query", if the user hasn't explicitly asked for such a value?

Comment by Craig Wilson [ 12/Aug/15 ]

We can certainly change future drivers to not pass null, but any existing driver that is currently doing this under whatever scenario will break. Not to mention any user code running the command through the generic run command interface in any driver.

Comment by David Storch [ 12/Aug/15 ]

We introduced additional validation to the distinct command parameters in https://github.com/mongodb/mongo/commit/bc4572c985a6d9dca5721ec45e88a19061f3842e under SERVER-15020. Specifically, we now require that either

  1. there is no field called "query", or
  2. there is a field called "query" of type BSONObj.

This simplified the parsing code, and also is consistent with the documentation of the distinct command (http://docs.mongodb.org/manual/reference/command/distinct/). However, if existing drivers rely on passing a BSON element of type null for the "query" field, we may have to relax the validation.

Generated at Thu Feb 08 03:52:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.