1
해시 필드로 사용자 유형을 저장하는 웹 애플리케이션이 있습니다. 나는 많은 컬렉션을 가지고있다. 해시 필드를 처리하는 가장 좋은 방법은 무엇입니까?문서 모음의 프로세스 해시 Mongoid
class Community
include Mongoid::Document
class UserRoles
Admin = :a
Moderator = :m
end
include Mongoid::Timestamps
field :un, as: :username, type: String
field :nm, as: :name, type: String
field :suids, as: :special_user_ids, type: Hash
has_and_belongs_to_many :users
end
이제 많은 커뮤니티가 있고 많은 사용자가 있고 각 사용자는 많은 중재자를 가질 수 있습니다. 그래서 스페셜 사용자에게는 해시로 저장합니다. 로그인 한 현재 사용자, 그는 내가이 시도 지역 사회
분명히이 나던 작품의의 운영자/관리자 인 경우
지금 내가 어떻게 계산하는 것입니다. 처리 할 단일 문서가 있으면 작동합니다. 그리고 내 솔루션 doesnt는 왜 해시가 처음에 사용되는 목적을 제공합니다.
# suids = []
# @communities = Community.all
# suids << @community.special_user_ids.collect { |k, v| k }
# //code doesnt find special_user_ids as it has too many documents to deal with.
# communities_path(@community.id)
나는 주어진 커뮤니티의 모든 관리자/사회자를 찾을 수있는 작업 코드가 있습니다. 원하는 지역 사회에 대한
def admins
@community = Community.find(params[:id])
@users = User.where(:id.in => @community.special_user_ids.collect { |k, v| k })
end
을 commmuniteis하지만 내 질문은 어떻게 취득 할 수있는 관리자를 얻을 수 ig하다 모든 커뮤니티의 관리자 목록 '# @communities = Community.all # suids << @ community.special_user_ids.collect {| k, v | k}'오류가 발생했습니다. 분명히 많은 별개의 문서에서 키 값을 얻을 수 없습니다. –
해시를 사용하여 효율적으로 작동하는 방법은 있습니까? –