【问题标题】:MongoDB - How to select only numeric strings / Check whether string is numeric in mongo-shellMongoDB - 如何仅选择数字字符串/检查字符串在 mongo-shell 中是否为数字
【发布时间】:2013-05-17 21:57:41
【问题描述】:

我有一个集合,其中字段是字符串,但这些字符串可以在其中包含数值,例如:

我的对象:{
示例:[
{例如:“单词”,...},
{例如:“更多单词”,...},
{例如:“111”,...},
{例如:“4502”,...}
...
]
...
}

如何查询“111”和“4502”等字符串格式的数值?

【问题讨论】:

    标签: mongodb mongo-shell


    【解决方案1】:

    您可以在查询对象中使用正则表达式来做到这一点:

    // Select docs where at least one examples element contains an example value
    // that's made up only of digits.
    db.test.find({'examples.example': /^\d+$/})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-28
      • 2010-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多