使用Mongo集合中的特殊字符 [英] Working with special characters in a Mongo collection

查看:206
本文介绍了使用Mongo集合中的特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无法删除的集合,我假设其名称中的-"是特殊字符.在MongoDB中,转义特殊字符的最佳方法是什么?

I have a collection I'm unable to drop, I'm assuming that the "-" in its name is a special character. In MongoDB, what is the best way to escape special characters?

> db.tweets.drop();
true

但是

> db.tweets-old.drop();
ReferenceError: old is not defined (shell):1

我试图用引号(单引号和双引号)和斜杠转义,但没有任何效果.

I've tried to escape with quotes (both single and double) and a slash, but nothing works.

推荐答案

以下作品:

db["tweets-old"].drop();

它称为方括号符号,它使您可以在属性名称中使用特殊字符.

It's called the square bracket notation, which allows you to use special characters in property names.

这篇关于使用Mongo集合中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆