Mongoid:查询一系列 ASCII 字符

发布于 2024-12-25 20:39:30 字数 209 浏览 1 评论 0原文

我在基于 Mongoid 的类中有一个带有名为 named 的字符串字段的集合。我希望能够查询 name 字段中以 a 到 f 中的字母开头的所有文档,不区分大小写。通过 Mongoid 执行此操作的最佳方法是什么?我假设该接口与 ActiveRecord 类似,因此如果可以在 ActiveRecord 中完成,那么也可以通过 Mongoid 完成。

I have a collection with a string field called named in my Mongoid based class. I'd like to be able to query for all documents that begin with the letters in the a through f in the name field, case insensitive. What's the best way to do this through Mongoid? I'm assuming the interface is similar to ActiveRecord, so if it can be done in ActiveRecord, it can probably be done through Mongoid as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最舍不得你 2025-01-01 20:39:30

这可以解决问题

  Yourcollection.where(:name => /^[a-f]/i )

i - 不区分大小写

This will do the trick

  Yourcollection.where(:name => /^[a-f]/i )

i - for case insensitive

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文