Questions tagged [mongodb-ruby]

Officially supported Ruby driver for MongoDB.

The MongoDB Ruby driver is the officially supported Ruby driver for MongoDB. It’s written in pure Ruby and is optimized for simplicity. It can be used on its own, but it also serves as the basis of several object mapping libraries, such as Mongoid.

Links

Related tags

50 questions
2
votes
1 answer

Using DBRef in mongo ruby driver: (undefined method `bson_type' for #)

When I try to use DBRef in the mongo ruby driver (creating a new DBRef object and including in a document which I am inserting into a collection), I get this error that I cannot make heads nor tails of: NoMethodError (undefined method `bson_type'…
2
votes
1 answer

MongoDB driver ruby, remove field in document

I am triying remove field in a big document, therefore I would like to do something: collection.update({'_id' => @id}, {"$unset" => {'herField'}) But it is not possible. I don't want to rewrite entire document, any idea? EDIT: I am using…
ie8888
  • 171
  • 1
  • 10
2
votes
1 answer

Mongoid 3.1.4 undefined method 'has_key?' when calling 'Document.create'

I'm having a problem trying to use Mongoid (v 3.1.4) to persist a (really simple) entity to MongoDB (v 2.4.4). I'm using MRI and Ruby 2.0.0-p195 on OS X. Here's my class (Person.rb): require 'mongoid' class Person include Mongoid::Document …
Gaston
  • 840
  • 1
  • 18
  • 27
2
votes
1 answer

Mongoid: retrieving documents whose _id exists in another collection

I am trying to fetch the documents from a collection based on the existence of a reference to these documents in another collection. Let's say I have two collections Users and Courses and the models look like this: User: {_id, name} Course: {_id,…
balu
  • 23
  • 3
1
vote
2 answers

Ruby on Rails and MongoDB

I have a new Ruby on Rails installation where I can see the default start-page. I followed this guide in order to install MongoDB to Rails. Now I get this error when running rake test: **Notice: C extension not loaded. This is required for optimum…
dimme
  • 4,393
  • 4
  • 31
  • 51
1
vote
2 answers

Cannot find Document with Ruby and MongoDB when using ObjectId

I have some code written in Ruby 1.9.2 patch level 136 and I'm have an issue where when I perform a find via the _id in the raw ruby mongo driver I get a nil when trying to use a value from a csv file. Here's the code: require 'mongo' require…
Donn Felker
  • 9,553
  • 7
  • 48
  • 66
1
vote
2 answers

Embedding documents in existing documents with the Ruby Driver for MongoDB

I'm trying to embed a document inside an existing document using the Ruby Driver. Here's what my primary document looks like: db = Mongo::Connection.new.db("Portfolios") project_collection = db.collection("Projects") new_Project = { :url =>…
Billy Coover
  • 3,827
  • 5
  • 36
  • 50
1
vote
3 answers

Rails 3 + MongoDB: How to do a nested query?

I am using Ruby Mongo Driver. @surname = coll2.find("name" => {"surname" => "testing"}) Shouldn't this be working? I get no results. I have {"name" : { "surname" : "testing" }}
Donald
  • 243
  • 4
  • 10
1
vote
1 answer

Return JSON with data from MongoDB

I am fetching data from MongoDB as follows: @bs = coll2.find("date" => {"$gte" => initial_date, "$lte" => Time.now.utc}) It works fine but when I render @bs, it sends empty. render :json => @bs If I do a @bs.each and render each one as json, it…
Donald
  • 243
  • 4
  • 10
1
vote
1 answer

Limitation in retrieving rows from a mongodb from ruby code

I have a code which gets all the records from a collection of a mongodb and then it performs some computations. My program takes too much time as the "coll_id.find().each do |eachitem|......." returns only 300 records at an instant. If I place a…
1
vote
1 answer

Ruby Mongo Driver Projection Elemmatch

Following the code in http://www.w3resource.com/mongodb/mongodb-elemmatch-projection-operators.php I have set up a test database using the ruby mongodb driver. For those following along at home, you first need to install the mongo driver as…
Elias
  • 11
  • 2
1
vote
0 answers

Mongomapper throwing error message multiple times

I have a simple Model - Shop in my Ruby/MongoMapper application. I have no idea why sometimes I only get one error message, and sometimes I get three error messages like this one: 'Validation failed: User has already been taken, User has already…
meso_2600
  • 1,940
  • 5
  • 25
  • 50
1
vote
1 answer

Mongodb-Ruby Limiting to specific fields

I'm having some problems limiting fields in result set from mongodb using the Ruby API. I have a mongo collection where I am storing information about files. One of the fields is 'image_filename'. I am attempting to return the fields and the id for…
awfulHack
  • 857
  • 1
  • 10
  • 25
1
vote
1 answer

Query a Many-to-Many relation in MongoDB

I am reading MongoDB in Action and when talking about querying many-to-many relationships in a Document, I'm having difficulty understanding how he wrote his example query (using the Ruby driver). The query is finding all products in a specific…
Bohn
  • 26,091
  • 61
  • 167
  • 254
1
vote
1 answer

How to update nth element inside an array without $pull or $pop?

How to update value of the nth position element inside an array? I want to update index 2 of category_id. One solution is ($pop or $pull) and $addToSet. Is there any other solution? Array ( [_id] => MongoId Object ( [$id] => 4f93ae990c211da128000004…
P K
  • 9,972
  • 12
  • 53
  • 99