[SERVER-2770] Any collection name on db w/corresponding function name fail Created: 16/Mar/11  Updated: 24/Mar/20  Resolved: 24/Mar/20

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Scott Hernandez (Inactive) Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Won't Fix Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-3879 Mongo allows for creation of collecti... Closed
Operating System: ALL
Participants:

 Description   

For example the config.version collection in sharding config is not accessible from the shell since the version function is returned.

We should check if the collection exists before returning the function:

> use config
switched to db config
> db["version"].find()
Wed Mar 16 08:23:22 TypeError: db.version.find is not a function (shell):1
> db["version"]
function ()

{ return this.serverBuildInfo().version; } If there is a collection we should use that, and print a warning message about the naming conflict. $ mongoexport -d config -c version connected to: 127.0.0.1:37017 { "_id" : 1, "version" : 3 }

exported 1 records



 Comments   
Comment by Ratika Gandhi [ 24/Mar/20 ]

Fixing this would be backwards incompatible with existing scripts so please use the workaround of calling getCollection directly. 

Comment by Brian [ 23/Apr/12 ]

related:
https://jira.mongodb.org/browse/SERVER-5616

Comment by Mark Waschkowski [ 07/Apr/11 ]

ya, I ran into this when I named a collection 'auth'. it was a pain to find out what the problem was. The should be fixed, it is a bug. If a name is reserved, or there are going to be side effects, at the very least a warning should be shown in the log, developers shouldn't have to track this kinda thing down.

I kept getting:

typeerror "find is not a function"

or when trying to save:

Thu Apr 07 13:36:28 TypeError: db.auth.save is not a function (shell):1

Comment by Scott Hernandez (Inactive) [ 18/Mar/11 ]

You can use db.getCollection("<coll-name>") to get around this issue, but I still think it is an ugly solution.

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