mongoid

Rethinking relational many-to-many relationships for MongoDB

I am just starting a new Rails 3 project using Mongoid ORM for MongoDB. There is just one thing I can not get my head around, and that is how to effectively have a many-to-many relationship. Now there is a good chance that I may be approaching this problem wrong, but as far as I know, there is at least two containers in my project that...

'validates_presence_of' doesn't work well in Mongoid?

There are two classes: class Person include Mongoid::Document field :name embeds_many :addresses end class Address include Mongoid::Document field :city field :street validates_presence_of :city, :street end We can see, we have validated the city and street should be present. But see following code: person = Person...

Pickle with cucumber, machinist and Mongoid

I'm using pickle 0.3.0 with rails, cucumber and mongoid. I do found that pickle0.3.0 automatically finds the ORM. But while I wrote a cucumber scenario and tested it, It didn't find any pickle steps. Here is the sample: Scenario: logging in user Given the following users exists |name| |John| |white| But didn't find pickle ste...

Problem with file uploads in a nested form using Rails3 with Mongoid and Carrierwave

Im having a problem transferring an SQLlite Rails 3 app over to a Mongoid Rails 3 app. In the SQLlite version, I am easily able to include an image upload form (using Paperclip) from one model ('image') within a nested form from another model ('product'). Here's my 'new' product form: <%= form_for @product, :html => {:multipart => t...

Mongoid - getting all attributes including embedded documents

Is there an easy way to get all attributes of a Mongoid document, including those of embedded documents? For example, if I have the following documents: class Person include Mongoid::Document embeds_many :phone_numbers field :name end class PhoneNumner include Mongoid::Document embedded_in :person, :inverse_of => :phone_numb...

How to implement mongoid many-to-many associations?

I want to port a social network to Mongoid. The join table between friends is very large. Is there any way for Mongoid to handle this join table out of the box? I've seen a couple of in-model roll-your-own solutions to it, but nothing the looks efficient. Is there a way to handle this? Or is this a case where I shouldn't be using Mo...

update embedded documents mongodb with mongoid

Hello frens.. I am having problem updating the embedded documents in mongodb. I have a following scenario. A User model has address as the embedded docs. I am able to embed the address to the parent model ie; User model but i still cant figure out how to update the address embedded even though i have the _id of the address embedded Plea...

mongoid references_many referenced_in not working rails

Hello frens, I have a problem with referenced_many and referenced_in relation model. My model is of following. Student references_many mobile_numbers MobileNumber referenced_in Student Now when i try to do @mobile = MobileNumber.first @mobile.student It pops error saying Document not found for class Student with id(s) 4c47e74ff1936f05f...

What's the best tutorial for learning Mongoid?

I'm new to Mongo DB and Mongoid (and still kinda new to Ruby on Rails). Since Ryan Bates dosen't happen to have a Mongoid Railscast, I need pointers to other good tutorials/screencasts. Thanks! ...

validates_associated model with condition

hello frens. I have the following validates_associated scenario class Parent include Mongoid::Document validates_associated :son validates_associated :daughter end when i create a parent, either of son or daughter is only created not both. Now my problem is, when i try to create parent with son, then validation fails due to daug...

Best Practice Mongoid:NestedResources

Hello Mongo Friends, I'm starting off with a small Rails3:MongoDB:Mongoid project and came along some questions that's nature is more architectural. When to use nested resources, and how deep to nest? I'm not a friend of nested routes at all, but they become handy if not stacked deeper than 2 resources and document oriented database...

What's the way to translate model attributes in rails with mongoid?

I've problem with mongoid and model translations. When I'm trying use mongoDB on my model I haven't idea to translate attributes and model name. It's normally in *.yml files but in this time this doesn't work. Any ideas? ...

Embed in many documents

class Person include Mongoid::Document field :name embeds_many :addresses end class Company include Mongoid::Document field :name embeds_many :addresses end class Address include Mongoid::Document embedded_in :addressable, inverse_of :addresses end I tried something like this company = Company.first person = Person.f...

trigging after_save on an embedded item when assigning it via '<<' in mongoid?

I was wondering if there was a way to trigger the after_save callback on an embedded_in object in Mongoid mapper. Example: i = Image.new(:file => file) user.images << i # => i.after_save should be triggered here I'm aware that if I call i.save after words, it will fire, however really hard to remember to do that throughout my code. ...

mongoid new versus build

hello frens why mongoid dosen't insert id when calling new on an association, but inserts id when calling build on an association? Is this a bug or this is how it works in mongoid? ...

Rails Mongoid version error

Attempting to start the WEBrick server on a Rails 3 / Ruby 1.9.1 with Mongoid errors with: "MongoDB 1.4.0 not supported, please upgrade to 1.6.0 (Mongoid::Errors::UnsupportedVersion)" ... but mongo --version: MongoDB shell version: 1.6.1 Anyone else seen this? Pretty new to Ruby so apologies if I'm asking a stupid questi...

:method => 'delete' in link_to doesn't seem to work in Rails 3?

I have code like this in a Rails 3 app I'm working on <% @positions.each do |position| %> <tr class="<%= cycle("", "alternate") %>"> <td><%= position.name %></td> <td class="actions"> <%=link_to 'edit', edit_position_path(position), :class => 'edit' %> | <%=link_to 'delete', position_path...

Problem with getting a name string from a query

Hello all, I'm pretty new to rails and mongoid and I have a problem with extracting a string out of a query. I have a class Filteroption class Fieldoption include Mongoid::Document field :name, :type => String field :option_id, :type => Integer end and with this entries +--------------------------+-------------...

Mongomapper documentation?

I have stumbled upon Mongoid which has great documentation: http://mongoid.org/docs/associations/ But I have heard that MongomMapper is de-facto for Rails. Where do I find API documentation for using Mongomapper? ...

how to mongoid projects <=has_many=> users

Hello all, I just began using Mongoid last week. I am running into this association problem which I am unsure if my approach is correct. So i thought I would ask for some opinion I have a User model and a Project model class User include Mongoid::Document field :email end class Project include Mongo...