如何规范化 Mongo 中的输入 - Ruby [英] How to normalize input in Mongo - Ruby

查看:31
本文介绍了如何规范化 Mongo 中的输入 - Ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一些我在 Mongo 中导入的非常大的第三方 CSV 文件.问题是这些文件的标题非常不一致.一些文件包含全小写、一些混合大小写和一些全大写标题.文件导入后,有没有办法不敏感地查询集合大小写?

I am dealing with some very large third party CSV files which I import in Mongo. The issue is that the headers on these files are very inconsistent. Some files contain all lowercase, some mixed case and some all uppercase headers. After the file is imported, is there a way to query a collection case insensitively?

简而言之,我能做到:

 @collection.find('AB' => value) so that it's true for fields 'ab' or aB' as well?

有没有办法在导入时规范这些标头?或者可能有另一种方式?

Is there a way to normalize these headers at the time of import? or may be there's another way?

建议重复的问题是针对值的正则表达式搜索,而不是字段本身

The question suggested as a duplicate is for regex searches on values and not the field itself

推荐答案

对于 字符串类文档.例如,.strip! 很适合用来删除多余的空白..downcase! 可用于规范化大小写.您可能会在文档中发现其他有用的内容.这是初级到中级 Ruby 编程的最佳资源之一.一旦掌握了每个类的方法,就可以充分利用 Ruby 的强大功能.

You should use the built-in Ruby methods for the String class documentation. For example, .strip!, would be a good one to use to remove excess whitespace. .downcase! could be used to normalize the case. There are others you may find useful to use in the documentation. This is one of the best resources for beginner to intermediate level Ruby programming. Once you master the methods of each class, you can leverage the full power of Ruby.

这篇关于如何规范化 Mongo 中的输入 - Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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