繁体   English   中英

MongoDB在db-name中转义特殊字符

[英]MongoDB escape special characters in db-name

有谁知道我如何在mongodb控制台中使用像“ abc-123”这样的数据库名称在一个命令中执行以下操作

 use abc-123;
 db.Configuration.find()

我尝试了类似的东西

 ['abc-123'].Configuration.find()

但没有任何效果。

感谢您的帮助!

您可以使用db.getSibling()来执行此操作-

> db.getSiblingDB("abc-123").Configuration.find()

{ "_id" : ObjectId("4fd20ac548b3c185dd9f8e5c"), "name" : "mongo" }
{ "_id" : ObjectId("4fd20ac748b3c185dd9f8e5d"), "x" : 3 }
{ "_id" : ObjectId("4fd20b9648b3c185dd9f8e5e"), "x" : 4, "j" : 1 }
{ "_id" : ObjectId("4fd20b9648b3c185dd9f8e5f"), "x" : 4, "j" : 2 }
{ "_id" : ObjectId("4fd20b9648b3c185dd9f8e60"), "x" : 4, "j" : 3 }
{ "_id" : ObjectId("4fd20b9648b3c185dd9f8e61"), "x" : 4, "j" : 4 }
{ "_id" : ObjectId("4fd20b9648b3c185dd9f8e62"), "x" : 4, "j" : 5 }
{ "_id" : ObjectId("4fd20b9648b3c185dd9f8e63"), "x" : 4, "j" : 6 }
{ "_id" : ObjectId("4fd20b9648b3c185dd9f8e64"), "x" : 4, "j" : 7 }
{ "_id" : ObjectId("4fd20b9648b3c185dd9f8e65"), "x" : 4, "j" : 8 }
{ "_id" : ObjectId("4fd20b9648b3c185dd9f8e66"), "x" : 4, "j" : 9 }
{ "_id" : ObjectId("4fd20b9648b3c185dd9f8e67"), "x" : 4, "j" : 10 }
......
......

这是指向MongoDB的命令参考列表的链接,其中讨论了getSibling的更多内容-http: //docs.mongodb.org/manual/reference/commands/

此外,建议保留数据库名称字母数字。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM