[SERVER-13791] Cannot access collection 2001_ABC Created: 30/Apr/14  Updated: 03/Jul/17  Resolved: 30/Apr/14

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

Type: Bug Priority: Minor - P4
Reporter: Avi Levy Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mongo.exe and importutility are being run on windows 64.
Mongod is version 2.6.0 on linux


Issue Links:
Duplicate
is duplicated by SERVER-29953 Numeric collection name Closed
Operating System: ALL
Steps To Reproduce:

Create a text file with sample json objects.
Create a collection named 2001_ABC using the import utility:
mongoimport.exe --host <host:port> -d <databasename> --collection 2001_ABC -file D:\Avi\1.json

Connect to the instance with mongo.exe
use <databasename>
show collections

You should see 2001_ABC in the list.

in mongo.exe do:
db.2001_ABC.drop
It should be dropped, but instead you get a syntax error.

Participants:

 Description   

I cant access/delete a collection through the client (mongo.exe).
The collection was created using the import utility.
(Probably the reason is the collection name starts with a number)

I can see the collection when doing 'show collections'.
When I try to drop it i get an error:
> show collections
2000_ABC
2000_Capped1G
2001_ABC
Col_2000_1G
system.indexes
system.profile
> db.2001_ABC.drop
2014-04-30T15:16:37.261+0300 SyntaxError: Unexpected token ILLEGAL
>



 Comments   
Comment by Avi Levy [ 30/Apr/14 ]

Thanks for the reply!

Comment by Scott Hernandez (Inactive) [ 30/Apr/14 ]

In javascript variable/function names must start with a letter, so that form is invalid, and generates an error in the javascript parser. To access the collection in javascript you must use one of these forms:

var coll = db["2000_ABC"]
var coll = db.getCollection("2000_ABC")
coll.drop();

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