[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 When attempting, e.g. an insert into db.stats the error |
| Comments |
| Comment by Githook User [ 13/Oct/17 ] |
|
Author: {'email': 'stennie@cpan.org', 'name': 'Stephen Steneker', 'username': 'stennie'}Message: |
| Comment by Githook User [ 13/Oct/17 ] |
|
Author: {'email': 'stennie@cpan.org', 'name': 'Stephen Steneker', 'username': 'stennie'}Message: |
| 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. |