Questions tagged [mongoid4]

Version 4 of Mongoid, an Object-Document-Mapper (ODM) for MongoDB with Ruby. Use this tag for questions relating to this specific version.

Version 4 of Mongoid (an Object-Document-Mapper (ODM) for MongoDB)), which is compatible with Rails 4. For a deeper description of Mongoid, see the main Mongoid tag.

Primary tag:

Homepage

104 questions
1
vote
1 answer

passing config from rails4.1 secrets.yml to mongoid.yml

How can I pass config from Rails 4.1 secrets.yml file to mongoid.yml assuming I have the scenario below: config/secrets.yml file default: &mongodb mongodb_host: <%= ENV['TRG_MONGODB_HOST'] %> mongodb_host_port: <%= ENV['TRG_MONGODB_HOST_PORT']…
brg
  • 3,915
  • 8
  • 37
  • 66
1
vote
1 answer

rails-4 mongoid-4 query to find all record gives undefined method `to_sym' for nil:NilClass

I am using Rails 4.1.4, Mongoid 4.0 and ruby 2.1.2p95. From my controller index that always returns undefined method `to_sym' for nil:NilClass. There are records in the database and from rails console, running thesame command @email_templates =…
brg
  • 3,915
  • 8
  • 37
  • 66
1
vote
1 answer

How to combine combine any_of with between in Mongoid 4?

I have read in this SO post this you can combine any_of with between like this: webshop = Webshop.first webshop.orders.any_of( webshop.orders.between(:datetime_pending, [Time.zone.now-7.days, Time.zone.now]).selector, # An error is raised here. …
Cjoerg
  • 1,271
  • 3
  • 21
  • 63
1
vote
1 answer

Rails 4 + Mongoid 4: Model.only("field").to_a not working as before

I just started a new project in Rails 4 and Mongoid 4 beta and an old behaviour that I used a lot in Mongoid 3 is not working anymore. Before I used to write Model.only("field").to_a and I would get an array with id and field, all other fields were…
Oktav
  • 2,143
  • 2
  • 20
  • 33
1
vote
1 answer

Not persistent id in Embedded Document in Mongoid 4

I use Mogoid first time (current beta with Rails-API 4 support). I use it to preserve user forms as one document with embedded documents. In update method in controllers I use this construct to create new card if returned card don't have…
ArturSkowronski
  • 1,722
  • 13
  • 17
1
vote
1 answer

using mongodb 2.6 multipolygon support with mongoid

I'm having the following model: class include Mongoid::Document field :polygons, type: Hash index({"polygon" => "2dsphere"}) end When i try to insert the following document I get an error: { _id: ObjectId('53467c7f476f6c551c020000'), …
Dominik Goltermann
  • 4,276
  • 2
  • 26
  • 32
1
vote
1 answer

Mongoid embedded model index not working

I have a company that contains products: class Company include Mongoid::Document include Mongoid::Timestamps embeds_many :products index({"products.code" => 1}, {sparse: true, unique: true}) end But when I create products(in the same…
Jirico
  • 1,242
  • 1
  • 15
  • 29
1
vote
2 answers

fresh Rails-4.1.0rc1 controller index throwing undefined method `to_sym' for nil:NilClass

When I create a fresh app with rails and sqlite and start the server and to to the index action for the controller, it does no throw a nil error even when no record has been created. But I do thesame with mongoid and navigate to the index action, I…
brg
  • 3,915
  • 8
  • 37
  • 66
1
vote
2 answers

mongoid combination of any_of and between

I need to achieve something like: queryable.any_of( between(:average_nightly_min_price, [10,100]), between(:average_nightly_max_price, [110,1100]) ) is it possible using the combination of any_of and between. Or any other…
Muntasim
  • 6,689
  • 3
  • 46
  • 69
1
vote
1 answer

syntax error, unexpected keyword_or scope

I'm running Feed.history but It's raising the error above at the title because of the scope line I use in Feed model: scope :history, -> { or({:end.ne => nil}, {:end.lt => Time.current}) } what and why?!!
Zakwan
  • 1,072
  • 2
  • 11
  • 22
1
vote
0 answers

Mongoid Criteria unexpected results when searching a document by id

I have a Mongoid Criteria of users and I want to find a user. Given a user that I'm sure doesn't exists in the criteria: >> users.where(email: user.email).exists? => false >> users.map(&:id).include?(user.id) => false When I search by id I always…
cortex
  • 5,036
  • 3
  • 31
  • 41
1
vote
1 answer

Batch insert multiple records with Mongoid?

I am reading through this Stackoverflow answer about how to insert multiple documents in Mongoid in one query. From the answer I read: batch = [{:name => "mongodb"}, {:name => "mongoid"}] Article.collection.insert(batch) I need an example to…
Cjoerg
  • 1,271
  • 3
  • 21
  • 63
1
vote
2 answers

Rails4 Mongoid Paperclip does not upload file, but everything else

I have a Rails4 Project Using Mongoid and Mongoid-Paperclip. I have ImageMagick just set up and the commands seem to work. The Model, that holds the image gets created, all the image fields get filled. The only thing that does not work is the…
Stefan
  • 295
  • 3
  • 18
1
vote
1 answer

how to run code when embedded document is created

I have the following models: class User include Mongoid::Document embeds_one :courier, class_name: "Users::Courier" validates_associated :courier accepts_nested_attributes_for :courier end module Users class Courier include…
Dominik Goltermann
  • 4,276
  • 2
  • 26
  • 32
1
vote
1 answer

Mongoid: How to sync both sides of a HABTM relation?

I have two models: class User ... has_and_belongs_to_many :groups ... end class Group ... has_and_belongs_to_many :users ... end For some reason the group object doesn't have all the user_ids. Maybe, because I'm using mongoid 4 alpha…
cortex
  • 5,036
  • 3
  • 31
  • 41