mongomapper

How do I get cucumber and pickle working with mongo_mapper, machinist, and machinist_mongo?

爱⌒轻易说出口 提交于 2019-12-10 22:23:31
问题 I would like to get machinist, machinist_mongo, mongo_mapper, cucumber and pickle to play nice together. Currently I have machinist with all my blueprints configured and am using cucumber to do BDD. So far so good. My problem is I am having to write custom cucumber steps for all of my machinist blueprints. It is not really a problem per se, since it is not stopping me in my tracks, but as a .NET dev checking out rails, it feels really dirty to have to write a step for each blueprint whereas

Not equals in mongo mapper

安稳与你 提交于 2019-12-10 17:53:15
问题 I'm trying to run a query where I want to ignore records with a certain email address... @foo = Bar.all(:email => 'xxx') <--- Except I want to negate where this email address exists. Please let me know how I can do it. Thanks! 回答1: Or @foo = Bar.all(:email.ne => 'xxx') 回答2: Try: @foo = Bar.all(:email => {"$ne" => "xxx"}) 回答3: @foo = Bar.all(:email => {"$ne" => "xxx"}) 来源: https://stackoverflow.com/questions/3541528/not-equals-in-mongo-mapper

MongoMapper and more than one databases in application

风格不统一 提交于 2019-12-10 11:46:10
问题 Is it possible to use MongoMapper in application that stores its models in many databases? For example I have separated database for Users and another one for Orders and I want to model both User and Order using MongoMapper. Of course I can switch MongoMapper.connection attribute but it is potentially unsafe due to race condition. 回答1: You can set the connection per model: User.connection(Mongo::Connection.new('localhost', 27017)) 来源: https://stackoverflow.com/questions/6751568/mongomapper

Delete document from mongoDB

本秂侑毒 提交于 2019-12-10 09:32:15
问题 This might be a really stupid question, but I'm new to MongoDB, so bear with me. I've created a stand alone ruby class: require 'rubygems' require 'mongo' require 'bson' require 'mongo_mapper' MongoMapper.database = "testing" class Twit include MongoMapper::Document key :id, Integer, :unique => true key :screen_name, String, :unique => true ... Then I do the following with irb >> twit = Twit.all.first => #<Twit _id: BSON::ObjectId('4df2d4a0c251b2754c000001'), id: 21070755, screen_name:

Find documents including element in Array field with mongomapper?

我是研究僧i 提交于 2019-12-10 06:10:16
问题 I am new to mongodb/mongomapper and can't find an answer to this. I have a mongomapper class with the following fields key :author_id, Integer key :partecipant_ids, Array Let's say I have a "record" with the following attributes: { :author_id => 10, :partecipant_ids => [10,15,201] } I want to retrieve all the objects where the partecipant with id 15 is involved. I did not find any mention in the documentation. The strange thing is that previously I was doing this query MessageThread.where

Creating a form for editing embedded documents with MongoMapper

冷暖自知 提交于 2019-12-08 20:48:45
问题 I'm playing around with MongoMapper but I'm having trouble figuring out how to create a form for an object that has embedded documents. With ActiveRecord, I'd use fields_for but when asked if this would be supported a few months ago, MongoMapper author John Nunemaker wrote: "Nope and nope. It is really [not] that hard with attr_accessor's." OK, fair enough, but how do you write the form for this to work? I'm not interested in using the nested form implementations that are out there because I

Rails 3 Polymorphic Association between one MongoMapper model and one/many Active Record model/s

為{幸葍}努か 提交于 2019-12-08 05:26:56
问题 I have a Record model (Active Record) that stores some custom logs. Record is in polymorphic association with all the other model in my app, and I can effectively log what I want hooking my Record methods in the other controllers. What I need: To have the logs in a separate database. So I have to: Be able to manage two different databases in my apllication (one is Postgres/ActiveRecord and the other one is MongoDB/MongoMapper) Generate a polymorphic association between my Record model, now

MongoMapper OR clause on 2 columns - Rails 3.1.rc4

こ雲淡風輕ζ 提交于 2019-12-07 20:54:05
问题 How to perform something like this: User.where("private = 1 OR beta = 0") 回答1: See: http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24or That translates to: User.where(:$or => [{:private => 1}, {:beta => 0}]) 来源: https://stackoverflow.com/questions/7175328/mongomapper-or-clause-on-2-columns-rails-3-1-rc4

Querying distinct with MongoMapper

≡放荡痞女 提交于 2019-12-07 19:10:50
问题 How do I query distinct with MongoMapper? My query is: subscribedToThread = Comment.where(:subscribe_thread => 1).all But this will return many objects with the same user_id . I need to return just a distinct user_id . Is this possible? 回答1: I think you will need to drop down to the ruby driver in order to do this as I don't think you can do this with MongoMapper itself: subscribedToThread = Comment.collection.distinct("user_id", {:subscribe_thread => 1}) Calling the collection method on a

Mongo_mapper limit results

我的未来我决定 提交于 2019-12-07 18:08:48
问题 I have a query like this: @allJobs = Job.where(:merchant_id => session[:admin_id].to_s).sort(:start_date.desc).limit(100) When I run .count on this I get: jobs count 1720 I expect to see : jobs count 100 What am I doing wrong? If I try to run Job.all(query).limit(100) I get "undefined method limit for Array #foo" It seems there is no way I can get the results to restrict to 100 records sorted in descending order by start_date! UPDATE: I cannot even do something simple like this: @allJobs =