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
26
votes
4 answers

How can I use Mongoid and ActiveRecord in parallel in Rails 3?

I'm using rails 3, and began my application with ActiveRecord. Now, I have many models, and the relations are starting to get complicated, and some could be more simply expressed with a Document-Oriented structure, so I'd like to try migrating to…
noli
  • 15,927
  • 8
  • 46
  • 62
26
votes
1 answer

What inverse_of does mean in mongoid?

What inverse_of does mean in mongoid associations? What I can get by using it instead of just association without it?
freemanoid
  • 14,592
  • 6
  • 54
  • 77
26
votes
3 answers

Set default database connection Rails

My rails app has its own MySql database (and requires the mysql2 gem) but also needs to connect with an external MongoDB database for one particular model (and so I've included mongoid and bson_ext in the Gemfile). Now when I try to generate a…
Chris
  • 11,819
  • 19
  • 91
  • 145
25
votes
3 answers

MongoID Data Type for TEXT

Whats the best option to use for MongoID data type for the regular MongoDB TEXT data type. Wondering why MongoID doesnt have a data type TEXT. is it okay to use STRING type and store large amounts of data. P.S coming from SQL background.
Harsha M V
  • 54,075
  • 125
  • 354
  • 529
23
votes
5 answers

Use LIKE/regex with variable in mongoid

I'm trying to find all documents whose text contains the word test. The below works fine: @tweets = Tweet.any_of({ :text => /.*test.*/ }) However, I want to be able to search for a user supplied string. I thought the below would work but it…
Hinchy
  • 683
  • 2
  • 7
  • 19
22
votes
5 answers

How to reference an embedded document in Mongoid?

Using Mongoid, let's say I have the following classes: class Map include Mongoid::Document embeds_many :locations end class Location include Mongoid::Document field :x_coord, :type => Integer field :y_coord, :type => Integer …
Scott Brown
  • 278
  • 1
  • 3
  • 8
22
votes
5 answers

How to skip callbacks on Mongoid Documents?

My question is similar to this one How to skip ActiveRecord callbacks? but instead of AR I'm using Mongoid, It seems like that isn't implemented yet in the current version of Mongoid, so I'd like to know what should be an elegant solution to…
jpemberthy
  • 7,473
  • 8
  • 44
  • 52
22
votes
2 answers

Collection ID length in MongoDB

i am new to mongodb and stack overflow. I want to know why on mongodb collection ID is of 24 hex characters? what is importance of that?
ashish bandiwar
  • 378
  • 1
  • 3
  • 12
22
votes
6 answers

Pros and cons of using callbacks for domain logic in Rails

What do you see as the pros and cons of using callbacks for domain logic? (I'm talking in the context of Rails and/or Ruby projects.) To start the discussion, I wanted to mention this quote from the Mongoid page on callbacks: Using callbacks for…
David J.
  • 31,569
  • 22
  • 122
  • 174
22
votes
2 answers

Mongoid not in query

I have some trouble with mongoid: test "Test candidate" do User.create(:id => 1, :sex => User::Male, :country => 1, :city => 1) User.create(:id => 2, :sex => User::Female, :country => 1, :city => 1) User.create(:id => 3, :sex =>…
Mark Pegasov
  • 5,109
  • 9
  • 26
  • 30
21
votes
3 answers

Mongo DB Design, embedding vs relationships

I'm building a simple accounting system where a user has many bills. Now I'm trying to decide if bills should be its own collection, or nested within the user. I'm leaning towards the former but I've NEVER done any noSQL stuff so I'm just going by…
brad
  • 31,987
  • 28
  • 102
  • 155
20
votes
3 answers

Querying embedded objects in Mongoid/rails 3 ("Lower than", Min operators and sorting)

I am using rails 3 with mongoid. I have a collection of Stocks with an embedded collection of Prices : class Stock include Mongoid::Document field :name, :type => String field :code, :type => Integer embeds_many :prices class Price …
mathieurip
  • 547
  • 1
  • 6
  • 16
19
votes
4 answers

How can I get all field names of the Mongoid Document?

I'm building backend system, as written in Iain Hecker's tutorial: http://iain.nl/backends-in-rails-3-1 and I try to adapt it to MongoDB with Mongoid. So when I need to write in backend/resourse_helper.rb module Backend::ResourceHelper def…
Yuri Sidorov
  • 329
  • 1
  • 2
  • 16
19
votes
2 answers

Getting actual array of results using Mongoid

With a regular ActiveRecord/SQL setup in Rails, in console when I execute commands *.where, *.all etc., I get back the actual array of record items. However, after switching to Mongoid, I instead get back a criteria. How do I get the actual…
Newy
  • 38,977
  • 9
  • 43
  • 59