在MongoDB Shell中切换/使用<dbname>

问题描述

我是mongodb的新手。

据我所知,创建集群时,它会自动创建一个名为数据库

我现在的问题是在外壳中。 如何切换到该数据库并使用它? 如果我尝试切换到其他现有的数据库(使用本地/使用管理员),则可以。 我尝试使用,但收到一条错误消息,提示不是有效的数据库名称

Image provided - me trying to use < dbname > and getting an error

谢谢!

解决方法

您通过Compass GUI创建数据库,并使用无效字符: enter image description here

“问题”

来自mongodb文档:

https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Database-Names-for-Windows

Windows的数据库名称限制

对于在Windows上运行的MongoDB部署,数据库名称不能 包含以下任意字符:

/\. "$*<>:|?

示例: enter image description here

解决方案

删除该数据库(通过指南针)-并创建没有< >数据库。

主题之外::更好的做法是使用更多的语义数据库名称,例如TripsOrders等(而不是 db-name )。