使用Mongo集合中的特殊字符

编程入门 行业动态 更新时间:2024-10-10 15:20:37
本文介绍了使用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集合中的特殊字符

本文发布于:2023-11-25 21:12:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631366.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:特殊字符   Mongo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!