Mongoid OR查询语法 [英] Mongoid OR query syntax
问题描述
必须对此进行很多询问,但文献记录很少.在 http://mongoid.org/en/mongoid/docs/querying中没有提及. html
This must be asked alot but it is very poorly documented. There is no mention at http://mongoid.org/en/mongoid/docs/querying.html
我正在尝试检查用户是否存在(下面是AND查询),如何将其更改为OR
类型的查询
I'm trying to check whether a user exists (below is an AND query), how can I change it to an OR
type query
Username.where(:username=>@username, :email=>@email)
(电子邮件或用户名必须匹配).
(Either the email or the username must match).
我发现了一些非常复杂的在线方法,包括发送直接javascript(从): http://omarqureshi.net/articles/2010-6-17-using-or-in-mongoid
I have found some pretty complicated ways online including sending a direct javascript (from): http://omarqureshi.net/articles/2010-6-17-using-or-in-mongoid
肯定要有一个简单的清晰语法才能正确执行此操作?
Surely there must be a simple clear syntax to do this correctly?
推荐答案
是的,以前有更好的记录.试试这个:
Yeah, this used to be documented better. Try this:
Username.any_of({:username => @username},
{:email => @email})
这篇关于Mongoid OR查询语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!