Skip to content

Instantly share code, notes, and snippets.

@suruja
Created April 8, 2012 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suruja/2338760 to your computer and use it in GitHub Desktop.
Save suruja/2338760 to your computer and use it in GitHub Desktop.
class Post
include Mongoid::Document
embeds_many :comments
end
class Comment
include Mongoid::Document
field :content
embedded_in :post
end
post = Post.create
post.comments.create(:content => 'alpha')
post.comments.where(:content => 'alpha').length # => 1
post.comments.where("this.content == 'alpha'").length # => 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment