为什么 MongoDb 不在这个字符串中存储我的斜杠? [英] Why doesn't MongoDb store my slashes in this string?

查看:62
本文介绍了为什么 MongoDb 不在这个字符串中存储我的斜杠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我为什么这个命令在 MongoDB shell 客户端不起作用:

Can anyone tell me why this command doesn't work from the MongoDB shell client:

db.coll.update({'live':true},{$set:{'mask':"\D\D\D\D\D\D\D\D"}},false,true)

但是

db.coll.findOne({'id':'someId'})

返回掩码字段为:

"mask" : "DDDDDDDD",

斜线去哪里了?

我试过用 \\D 进行双重转义"并插入两个斜杠:

I've tried "double escaping" with \\D and that inserts both slashes:

"mask" : "\\D\\D\\D\\D\\D\\D\\D\\D",

MongoDB shell 版本:2.0.6,MongoDB 版本:2.0.5,OSX Lion

MongoDB shell version: 2.0.6, MongoDB version: 2.0.5, OSX Lion

谢谢

推荐答案

使用正则表达式(不带引号)

use regex notation (without quotes)

/\D\D\D\D\D\D\D\D/ 

或者使用四个斜线.

"////D" ==> "/D"

这篇关于为什么 MongoDb 不在这个字符串中存储我的斜杠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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