Rails Mongoid 显示所有使用 "where" 的文档

Rails Mongoid show all documents using "where"

我尝试将值作为参数传递给数组:

控制器:

@users = User.all.page(params[:page]).per(params[:per_page]).order(sort_by => sort_order).where(type: {'$all': ["#{params[:type]}"] })

现在,是否可以使用以下方法从集合中找到所有文档:

.where(type: {'$all': ['something_to_find_all_from type:'] })

?

假设params[:type] 是一个数组,您可以使用where 搜索所有用户,然后使用order 对这些结果进行排序。你可以找到一个类似的例子 here.

@users = User.where(:type.in => params[:type]).order(sort_by => sort_order).page(params[:page]).per(params[:per_page])

如果您正在寻找翻译的 mongoid 查询,您可以查看 this link

您的查询可能会是这样的 User.where(:type.all => params[:type])