[SERVER-16260] Some commands no longer accept values of the Symbol BSON type Created: 21/Nov/14  Updated: 15/Jan/15  Resolved: 08/Jan/15

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: 2.8.0-rc0
Fix Version/s: 2.8.0-rc5

Type: Bug Priority: Major - P3
Reporter: Emily Stolfo Assignee: Matt Kangas
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-16542 Shell helper for creating arbitrary B... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

For reference when reading the following: a Ruby symbol is represented in the form :symbol and is serialized to the BSON Symbol type.
Using the most recent Ruby driver (1.12.0.rc0), with MongoDB server version 2.6:

client = MongoClient.new
db = client['test']
db.create_collection(:foo)
db.drop_collection(:foo)
=> true

This is what mongosniff shows:

127.0.0.1:56381  -->> 127.0.0.1:27017 admin.$cmd  58 bytes  id:e	14
	query: { drop: "foo" }  ntoreturn: -1 ntoskip: 0
127.0.0.1:27017  <<--  127.0.0.1:56381   88 bytes  id:f	15 - 14
	reply n:1 cursorId: 0
	{ ns: "admin.foo", nIndexesWas: 1, ok: 1.0 }
 

With MongoDB nightly Nov-18-2014 and the most recent Ruby driver (1.12.0.rc0):

client = MongoClient.new
db = client['test']
db.create_collection(:foo)
db.drop_collection(:foo)
=> false

And this is the mongosniff output

127.0.0.1:56381  -->> 127.0.0.1:27017 admin.$cmd  58 bytes  id:13	19
	query: { drop: "foo" }  ntoreturn: -1 ntoskip: 0
127.0.0.1:27017  <<--  127.0.0.1:56381   94 bytes  id:14	20 - 19
	reply n:1 cursorId: 0
	{ ok: 0.0, errmsg: "no collection name specified" }

In looking at the commit that changed this behavior, other commands are probably affected as well.

Participants:

 Description   

The server no longer accepts the Symbol BSON type for some command values. In particular, the 'drop' command is affected.

I believe it is because of this commit https://github.com/mongodb/mongo/commit/d41f98bd0fdc3d392fc19aadfdc62a020d17fede



 Comments   
Comment by Githook User [ 08/Jan/15 ]

Author:

{u'username': u'kangas', u'name': u'Matt Kangas', u'email': u'matt.kangas@mongodb.com'}

Message: SERVER-16260 Accept Symbol BSON type arg for some commands

Followup to SERVER-16072

Add dbtest for commands that accept Symbol BSON type as collection name

Comment by Bernie Hackett [ 08/Dec/14 ]

I suppose then I'd change my recommendation to 1) in the Ruby driver, fix the drop_collection() helper and the command() helper, and similarly audit the rest of db.rb, 2) in the server, accept Symbol in all of the commands that were changed by the above commit, with a comment explaining why and a plan to remove it in 3.0.

I think this is a reasonable plan of action.

Comment by J Rassi [ 08/Dec/14 ]

Unlike the drop_collection() helper, the command() helper in the Ruby driver isn't actually explicitly documented to take symbols as values inside the "selector" argument, but sure, you're right, I wouldn't be surprised if applications are doing that anyway (though, note also that I do not believe that any server command accepts the Symbol type for any of its command-specific options during parsing). If it is expected that users will invoke the command() helper with symbol values, then the command() helper needs to be serializing those values to the String BSON type; it is a defect in the Ruby driver (or in the driver documentation for the command() helper, depending on how you look at it) that it is sending Symbol elements to the server in command objects, because the server is not going to handle them correctly (if any application currently is using the driver this way, it /will/ get broken by a future server release, I assure you).

I suppose then I'd change my recommendation to 1) in the Ruby driver, fix the drop_collection() helper and the command() helper, and similarly audit the rest of db.rb, 2) in the server, accept Symbol in all of the commands that were changed by the above commit, with a comment explaining why and a plan to remove it in 3.0.

Comment by Bernie Hackett [ 08/Dec/14 ]

rassi@10gen.com - the bigger issue is every driver has a generic command helper. That means in Ruby any command could have its name passed as a symbol. This change will potentially break a large number of applications, and not just those calling drop_database.

Comment by J Rassi [ 08/Dec/14 ]

emily.stolfo@10gen.com: could you please file/schedule a ticket to fix the drop_collection() helper in the 1.x-stable branch, and also perform an audit that all other helpers in db.rb correctly invoke to_s on the collection name before sending it to the server (so we can similarly deal with such helpers now)? In the past, it looks like we have resolved this by applying a fix to the Ruby driver (e.g. RUBY-317, though see also RUBY-260 and RUBY-804), but I would be in support of a server bandaid fix in this case due to the potentially large number of applications affected.

matt.kangas@10gen.com: I would recommend adding logic to handle Symbol /only/ in the drop command, with a comment indicating that it is needed because of bug in a helper the Ruby driver (I'd mention this ticket in the comment, and I'd also suggest filing another ticket in SERVER to remove this Symbol-specific parsing logic for 3.0). I just checked all of the other commands changed from d41f98bd, and none of them have a corresponding helper in the Ruby driver that could end up constructing a command object with a Symbol collection name; thus, we do not need to change the parsing logic in other commands.

Comment by Matt Kangas [ 21/Nov/14 ]

You're absolutely right. Noted.

Comment by Emily Stolfo [ 21/Nov/14 ]

While the BSON Symbol type has been deprecated, this is still a backwards breaking change in the server, regardless of whether newer Ruby driver versions continue to send it.

I believe the BSON Symbol type is 14.
15 is Code with scope.

Comment by Matt Kangas [ 21/Nov/14 ]

The BSON symbol type has been deprecated since 2011. Perhaps the Ruby driver should stop sending BSON type 15 14.

But since all Ruby drivers in the wild currently send it, the server should accept both String and Symbol values (BSON types 2, 15 14) for the commands modified in SERVER-16072.

(Corrected: Symbol is 0x0E, integer value 14)

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