我有一个无法删除的集合,我假设其名称中的“-”是一个特殊字符。在 MongoDB 中,转义特殊字符的最佳方法是什么?
> db.tweets.drop();
true
但是
> db.tweets-old.drop();
ReferenceError: old is not defined (shell):1
我尝试使用引号(单引号和双引号)和斜杠进行转义,但没有任何效果。
最佳答案
以下作品:
db["tweets-old"].drop();
它被称为 square bracket notation ,它允许您在属性名称中使用特殊字符。
https://stackoverflow.com/questions/9569976/