[DOCS-1857] Collection with - in name failed Created: 28/Aug/13  Updated: 11/Jan/17  Resolved: 28/Aug/13

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Bug Priority: Major - P3
Reporter: HVN Assignee: Sam Kleinman (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mongodb-linux-x86_64-2.4.6
Ubunt 12.04 LTS


Participants:
Days since reply: 10 years, 25 weeks ago

 Description   

Due to this doc, collection with - in name is okay.
http://docs.mongodb.org/manual/reference/limits/#Restriction%20on%20Collection%20Names

But this is what I got:
> db.salt-master.insert(

{"name": "HVN"}

)
Wed Aug 28 12:15:04.378 ReferenceError: master is not defined
> db.saltmaster.insert(

{"name": "HVN"}

)
> db.saltmaster.find()

{ "_id" : ObjectId("521d875f383d0080ca077962"), "name" : "HVN" }

So this maybe doc bug or core bug?



 Comments   
Comment by auto [ 28/Aug/13 ]

Author:

{u'username': u'tychoish', u'name': u'Sam Kleinman', u'email': u'samk@10gen.com'}

Message: DOCS-1857: note about getCollection
Branch: master
https://github.com/mongodb/docs/commit/98b817f25b864ad2eb5bb149b4765422243b4f68

Comment by Sam Kleinman (Inactive) [ 28/Aug/13 ]

This is a problem with the JavaScript shell. To specify collections in JavaScript they must be valid SavaScript operations, and the hyphen character is not valid JavaScript in this context. You can use the db.getCollection() method (http://docs.mongodb.org/manual/reference/method/db.getCollection/) as in the following operation to specify collections which have names that are not valid JavaScript symbols:

> db.getCollection('salt-master').insert({a:1})
> db.getCollection('salt-master').find()
{ "_id" : ObjectId("521dfb9d6bb74fcd826282e1"), "a" : 1 }

Generated at Thu Feb 08 07:42:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.