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

What is the length maximum for a string data type in MongoDB used with Ruby?

I wasn't able to find any information on the max length for a string data type in MongoDB on the main mongodb.org site. I'm coming from a relational database background and there are usually max lengths.
Goalie
  • 3,045
  • 5
  • 35
  • 46
36
votes
3 answers

Mongoid 3 + Heroku (MongoHQ) cause Moped::Errors::OperationFailure

With Rails 3, after upgrading from Mongoid 2.x to Mongoid 3.x, my Heroku + MongoHQ setup stopped working. Funny thing is, that my development & test frameworks and my whole test suite passes just fine. I suspect the problem is with my mongoid.yml…
herb
  • 840
  • 9
  • 16
34
votes
3 answers

Is it bad to change _id type in MongoDB to integer?

MongoDB uses ObjectId type for _id. Will it be bad if I make _id an incrementing integer? (With this gem, if you're interested)
just so
  • 1,088
  • 2
  • 11
  • 23
33
votes
4 answers

Mongo ids leads to scary URLs

This might sound like a trivial question, but it is rather important for consumer facing apps What is the easiest way and most scalable way to map the scary mongo id onto a id that is…
meow
  • 27,476
  • 33
  • 116
  • 177
33
votes
3 answers

How to deal with the timezone issue when storing dates in utc using mongod?

I have a mongodb collection where each document has some attributes and a utc timestamp. I need to pull out data from the collection and use the aggregation framework because I use the data from the collection to display some charts on the user…
Hrishi
  • 7,110
  • 5
  • 27
  • 26
32
votes
3 answers

Mongoid finders not working?

I have set up a rails3+mongoid application and when I open the rails console, none of the finders seem to work - http://d.pr/FNzC User.all User.find(:all, :conditions => { first_name => "John" }) both return: #
Hutch
  • 841
  • 1
  • 8
  • 9
31
votes
4 answers

Retrieving array of ids in Mongoid

how do you retrieve an array of IDs in Mongoid? arr=["id1","id2"] User.where(:id=>arr) You can do this easily if you are retrieving another attribute User.where(:nickname.in=>["kk","ll"]) But I am wondering how to do this in mongoid -> this should…
meow
  • 27,476
  • 33
  • 116
  • 177
31
votes
1 answer

Mongoid / Mongodb and querying embedded documents

I have Author and Book models. An Author has many embedded Books. Can I query the embedded Books, or do I have to fetch Authors first to get Books?
sewid
  • 341
  • 1
  • 3
  • 7
31
votes
3 answers

Rails, Mongoid & Unicorn config for Heroku

I am using Mongoid 3, with Rails 3.2.9 and Unicorn for production. Would like to setup a before_fork & after_fork for the connection to mongodb, found the following code for active record: before_fork do |server, worker| # Replace with MongoDB or…
ismail
  • 3,882
  • 5
  • 36
  • 47
31
votes
7 answers

How to query MongoDB directly from Ruby instead of using Mongoid?

I am writing a migration for a Rails application that uses MongoDB and Mongoid. My migration currently uses my models that use Mongoid to query and update records, but the performance is sub-par. I am essentially updating all records in a large…
Andrew
  • 227,796
  • 193
  • 515
  • 708
29
votes
5 answers

Rails 3: undefined method `page' for #

I can't get past this. I know I've read there isn't a page method for arrays but what do I do? If I run Class.all in the console, it returns #, but if I run Class.all.page(1), I get the above error. Any ideas?
Chris Bolton
  • 2,878
  • 6
  • 38
  • 57
28
votes
3 answers

How to get the resultant array from a Mongoid::Criteria without an "each" block

Our application uses ajax very heavily and as a result of this we have statements like var items = #{@items.to_json} in all our views. Now @items is being set in the controller as @items=Item.all. The problem is that @items is a Mongoid::Criteria…
Khaja Minhajuddin
  • 6,653
  • 7
  • 45
  • 47
28
votes
1 answer

Query on Mongoid Hash Field

I want to query on a Hash field for a Mongoid Class. I'm not sure how I can do this with conditions? Here is an example: class Person include Mongoid::Document field :things, :type => Hash end So, let's say that I have this: p =…
JP Richardson
  • 38,609
  • 36
  • 119
  • 151
27
votes
1 answer

Mongoid Scope Check If Array Field Contains Value

The solution for this question might look pretty simple, but I've been waving around with no answer. I'm using Mongoid in my Rails 4.1.4 app. I have a model which contains an Array field that will house String values. I need a Mongoid's scope in the…
Luis Crespo
  • 1,610
  • 1
  • 20
  • 33
26
votes
3 answers

Managing mongoid migrations

Can someone give me a short introduction to doing DB migrations in Rails using Mongoid? I'm particularly interested in lazy per document migrations. By this, I mean that whenever you read a document from the database, you migrate it to its latest…
Paul Biggar
  • 27,579
  • 21
  • 99
  • 152