简体   繁体   English

从mongodb中的文档开头删除“

[英]Remove " from start of documents in mongodb

I have a mongodb collection like this: 我有一个像这样的mongodb集合:

name: 'john'
family: '"smith"'

i want to remove " from first and end of family, for example convert '"smith"' to 'smith' . i know should use update and regular expression like this /^"/, but how? 我想从家庭首尾中删除" ,例如将'"smith"'转换为'smith' 。我知道应该使用update和正则表达式,例如/ ^“ /,但是如何?

Thanks for any reply. 感谢您的答复。

Javascript example: JavaScript示例:

> '"smith"'.replace(/^"|"$/g, '')
'smith'

/^"|"$/g matches leading quote ( ^" ) or ( | ) or trailing quote ( "$ ). /^"|"$/g匹配前导引号( ^" )或( | )或尾随引号( "$ )。

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

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