[DOCS-10863] Unclear documentation on use of reserved words in MongoDB shell Created: 04/Oct/17  Updated: 30/Oct/23  Resolved: 13/Oct/17

Status: Closed
Project: Documentation
Component/s: tools
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Minor - P4
Reporter: Steffan Mejia Assignee: Stennie Steneker (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 6 years, 17 weeks, 6 days ago

 Description   

There doesn't appear to be any documentation on the use of restricted words in collection names in the MongoDB shell, including some commonly used words.

Example keywords that might be commonly used for collections:

group
auth
stats
version
password
prototype

When attempting, e.g. an insert into db.stats the error
db.stats.insert is not a function is returned



 Comments   
Comment by Githook User [ 13/Oct/17 ]

Author:

{'email': 'stennie@cpan.org', 'name': 'Stephen Steneker', 'username': 'stennie'}

Message: DOCS-10863: Improve documentation on use of reserved words in MongoDB shell
Branch: v3.4
https://github.com/mongodb/docs/commit/52e5ac62037c61c2df0eaf9dbec083c0900a5d7c

Comment by Githook User [ 13/Oct/17 ]

Author:

{'email': 'stennie@cpan.org', 'name': 'Stephen Steneker', 'username': 'stennie'}

Message: DOCS-10863: Improve documentation on use of reserved words in MongoDB shell
Branch: master
https://github.com/mongodb/docs/commit/08a59721fbc3294ae5be451dc7964e0755262f95

Comment by Steffan Mejia [ 04/Oct/17 ]

I suggest the mongo shell introduction: https://docs.mongodb.com/manual/mongo/#working-with-the-mongo-shell be amended:

Original

If the mongo shell does not accept the name of the collection, for instance if the name contains a space, hyphen, or starts with a number, you can use an alternate syntax to refer to the collection, as in the following

to

Suggested

If the mongo shell does not accept the name of the collection, for instance if the name contains a space, hyphen, conflicts with a built-in function, or starts with a number, you can use an alternate syntax to refer to the collection, as in the following

Comment by Stennie Steneker (Inactive) [ 04/Oct/17 ]

These names aren't actually restricted from use, but conflicts with built-in mongo shell helpers/functions will make them less intuitively accessible. There is a reasonably long list but most functions use camel case so are less likely to conflict. You can preview by doing db.<tab><tab> to autocomplete top-level functions for the db object in an database without any collections.

If you want to avoid internal name clashes or use collection names that aren't valid JavaScript identifiers (i.e. those with an embedded space/hyphen or leading digit) there is a db.getCollection() shell helper: https://docs.mongodb.com/manual/reference/method/db.getCollection/.

This is also mentioned in the mongo shell introduction: https://docs.mongodb.com/manual/mongo/#working-with-the-mongo-shell.

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