Questions tagged [mongoid]

Mongoid is the official Ruby Object-Document-Mapper (ODM) for MongoDB.

Mongoid (pronounced mann-goyd) is an Object-Document-Mapper (ODM) for MongoDB written in Ruby. Mongoid as of version 5 is under the control and guidance of MongoDB as the official Ruby ODM.

The philosophy of Mongoid is to provide a familiar API to Ruby developers who have been using Active Record or Data Mapper, while leveraging the power of MongoDB's schema-less and performant document-based design, dynamic queries, and atomic modifier operations.

4728 questions
2
votes
1 answer

Mongoid observers not firing at all (rails 3.2.13, mongoid 3.1.3)

I think I followed the description of how to make observers exactly, Model page: class Page include Mongoid::Document field :title, type: String field :content, type: String end I have an observer (app/observers/page_observer.rb): class…
Daniel
  • 1,188
  • 11
  • 22
2
votes
1 answer

Rails blog using Mongoid - Auto generate Short URL on post creation

I have a simple blog engine using Rails and Mongoid ORM. I have 2 models in the blog, 'Article' and 'Url'. The Article model contains all of the post content, and the Url class is the generator function that takes the slug of the Article and…
Smith
  • 21
  • 1
2
votes
1 answer

Iterating over a collection in MongoDB for updates

I'm iterating over a collection (running Moped as Ruby driver) but how to update one field for every document? irb> session = Moped::Session.new(["127.0.0.1:27017"]) irb> session.use :demoapp irb> users = session[:users] irb> users.find.each {|u|…
ctp
  • 1,077
  • 1
  • 10
  • 28
2
votes
1 answer

form_for signature for Mongoid::Document subclass

I have a Mongoid document as : class Index include Mongoid::Document end And two subclasses for 'Index' as: class PercentileRankIndex < Index end class SocialStockIndex < Index end I want to create a form_for say 'PercentileRankIndex',…
Nitish Upreti
  • 6,312
  • 9
  • 50
  • 92
2
votes
1 answer

Destroy an embedded Mongoid document by specifying its "id" (instead of finding it through its parent)

I have these two models: class Presentation include Mongoid::Document embeds_many :presentation_rows end class PresentationRow include Mongoid::Document embedded_in :presentation end In my presentation_rows_controller.rb I have these lines…
Cjoerg
  • 1,271
  • 3
  • 21
  • 63
2
votes
3 answers

Rails Update Action fails with rails4, mongoid. Create ok

I have a dead simple rails application w/ rails4 and mongoid. I can create new datasets like a charm. But I just can't update existing datasets. Anyone has this issue? How does this work, what am I doing so wrong? Just created from scratch with…
jlxq0
  • 87
  • 1
  • 8
2
votes
0 answers

Mongoid embedded document to automatically save (trigger callbacks on) parent

If I have the following classes: class Bar include Mongoid::Document embeds_many :foos, :cascade_callbacks => true end class Foo include Mongoid::Document embedded_in :bar, :inverse_of => :foos end Is it possible to have this in such a way…
RemoteCTO
  • 818
  • 8
  • 21
2
votes
2 answers

What's the ideal way to model this with Mongoid? An issue with multiple models

I am noticing a relation problem that I may have created. I started off with a Photo model. An admin could upload photos and they would exist on the site. In a later iteration Albums were added into the codebase so that a collection of photos could…
Daniel Fischer
  • 3,042
  • 1
  • 26
  • 49
2
votes
1 answer

Mongoid: search in has_many relation

I'm using mongoid, and have the following code: class Users::User include Mongoid::Document field :username, type: String has_many :emails, class_name: "Users::Email" end class Users::Email include Mongoid::Document field :email, type:…
ole
  • 5,166
  • 5
  • 29
  • 57
2
votes
1 answer

Mongoid : Eager loading count on has_many association

I'm new with mongodb. I'm trying to list some documents, my class has a has_many association, I would like to display the number of documents from this association. Do I need to do some eager loading ? If I use includes all the documents will be…
Intrepidd
  • 19,772
  • 6
  • 55
  • 63
2
votes
3 answers

MongoDB/Mongoid: search for documents matching first item in array

I have a document that has an array: { _id: ObjectId("515e10784903724d72000003"), association_chain: [ { name: "Product", id: ObjectId("4e1e2cdd9a86652647000003") } ], //... } I'm trying to…
Andrew
  • 227,796
  • 193
  • 515
  • 708
2
votes
2 answers

mongoid configuration on ruby without framework

I try to write business logic of my application. It is all ruby classes. There is no database or no UI framework like Rails, Sinatra. I only have a Gem_file on business logic and, Gem_file only contain "mini_test" gem. I use mini_test for testing…
miyamotomusashi
  • 531
  • 7
  • 22
2
votes
0 answers

How to use Devise authorization in custom middleware

I have middleware for serving files from mongodb #serve_gridfs_file.rb class ServeGridfsFile def initialize(app) @app = app end def call(env) if env["PATH_INFO"] =~ /^\/grid\/(.+)$/ process_request(env,…
Aitvaras
  • 261
  • 4
  • 15
2
votes
1 answer

How to test mongoid model validations with message by shoulda?

I have a model with validations, like this: class Order include Mongoid::Document field :first_name, type: String field :last_name, type: String validates_presence_of :first_name, :message => "Can't be empty" validates_presence_of…
Denis Kreshikhin
  • 8,856
  • 9
  • 52
  • 84