mongomapper

mongodb function from rails

杀马特。学长 韩版系。学妹 提交于 2020-01-05 04:33:11
问题 I use mongomapper with mongodb for rails models. In the mongodb I have this function db.system.js.save({_id:'resumenTemporada',value:function(collection, condition){ var res= db[collection].group({ key:{}, reduce:function(obj,prev){ prev.ppa += obj.precipitation; if( obj.temperature < 5 && obj.temperature >0) prev.hf += obj.temperature/4; }, initial : {ppa:0,hf:0}, cond: condition}); return res ; } }); And get this output > db.eval("return resumenTemporada('stations',{nombre:'pua',fecha:{$gt:

MongoMapper and bson_ext problem

此生再无相见时 提交于 2019-12-31 22:20:51
问题 I can't get MongoMapper to work with my Rails app. I get this error message: **Notice: C extension not loaded. This is required for optimum MongoDB Ruby driver performance. You can install the extension as follows: gem install bson_ext If you continue to receive this message after installing, make sure that the bson_ext gem is in your load path and that the bson_ext and mongo gems are of the same version. I have installed DevKit and installed the gem: gem install bson_ext --no-rdoc --no-ri

Get first element in array and return using Aggregate? (Mongodb)

佐手、 提交于 2019-12-29 07:25:11
问题 How I get first element in array and return it in Mongo aggregate? I try run this code in mongo, but fail: db.my_collection.aggregate([ { $project: { resp : { my_field: { $slice: 1 } } }} ]) OBS : 'my_field' is a Array with 4 position, I need it return only first element. Return: uncaught exception: aggregate failed: { "errmsg" : "exception: invalid operator '$slice'", "code" : 15999, "ok" : 0 } 回答1: Currently, the $slice operator is unavailable in the the $project operation, of the

activerecord and mongo / mongo-mapper bridge

感情迁移 提交于 2019-12-24 06:19:20
问题 I have a project which I have used Active Record and which I'd like to add some new features using MongoDB. Rather than re-invent the wheel and re-write my entire site, how can I integrate 2 models together, one which use MongoMapper and the other ActiveRecord (postgres). I've found that others have done it successfully, but no examples: http://groups.google.com/group/mongomapper/browse_thread/thread/ec5ad00e18e7dd2c/887b8b0b904a8f73?lnk=gst&q=activerecord#887b8b0b904a8f73 For example, I have

activerecord and mongo / mongo-mapper bridge

房东的猫 提交于 2019-12-24 06:19:02
问题 I have a project which I have used Active Record and which I'd like to add some new features using MongoDB. Rather than re-invent the wheel and re-write my entire site, how can I integrate 2 models together, one which use MongoMapper and the other ActiveRecord (postgres). I've found that others have done it successfully, but no examples: http://groups.google.com/group/mongomapper/browse_thread/thread/ec5ad00e18e7dd2c/887b8b0b904a8f73?lnk=gst&q=activerecord#887b8b0b904a8f73 For example, I have

Does MongoMapper (or any other Mongodb adapter) have a method like “accepts_nested_attributes_for”?

[亡魂溺海] 提交于 2019-12-23 11:48:29
问题 I'm considering using mongodb on a new project, but before delving in, I'd like to know if it supports some key features. I know you don't need migrations, and you can add embedded objects,...but does all that mean it also behaves as if the 'accepts_nested_attributes_for' method is always there? Do you know of any other killer features that I should be aware of that would sway me for or against MongoDB? Here's a recent article I'm aware of, and that others may also be interested in: http:/

ERROR Errno::ECONNRESET: Connection reset by peer

走远了吗. 提交于 2019-12-23 06:50:14
问题 gem 'rails', '3.0.0' gem 'devise' gem 'bson_ext', '>= 1.0.7' gem 'bson', '>= 1.0.7' gem 'mongo_mapper', :branch => 'rails3', :git => 'http://github.com/jnunemaker/mongomapper.git' gem 'devise-mongo_mapper', :git => 'git://github.com/collectiveidea/devise-mongo_mapper' With the above setup I get the following errors on requests: Started GET "/users/sign_out" for 127.0.0.1 at 2010-09-27 13:16:30 +0300 Processing by Devise::SessionsController#destroy as HTML Redirected to http://localhost:3000/

“LIKE” command in MongoDB(mongomapper)

假装没事ソ 提交于 2019-12-22 08:55:53
问题 how to use filter data as sql do "LIKE" in MongoDB, instead I using gem mongomapper on my rails apps? .thanks 回答1: If you're looking for partial matches on a string you can query with a regular expression. Here's the relevant part of the mongomapper docs: http://api.mongodb.org/ruby/current/file.TUTORIAL.html#Querying_with_Regular_Expressions Worth noting this from the Mongodb docs: "For simple prefix queries (also called rooted regexps) like /^prefix/, the database will use an index when

Setting up mongomapper for multiple databases

岁酱吖の 提交于 2019-12-21 18:35:24
问题 How can I have one mongo model go to one database and another using another database? I've been send this link https://github.com/jnunemaker/mongomapper/blob/master/lib/mongo_mapper/plugins/persistence.rb and this stackoverflow answer is like my answer MongoMapper and more than one databases in application Where in my application do I set the connection for my Models? 回答1: The source link you posted is what you want. Those methods are all mixed-in to your models, so: class MyModel include

Handling MongoMapper EmbeddedDocument in Rails form

ぐ巨炮叔叔 提交于 2019-12-13 15:05:36
问题 First of all, I'm new to programming in general and new to Rails. I picked up Rails because it seems an easy language to start with. For my project I'm using MongoMapper with Rails. I'm trying to process an Embedded Document in the same form as the Document. I have the following model: class User include MongoMapper::Document key :email, String, :required => true key :first_name, String key :last_name, String key :role, String many :addresses timestamps! end class Address include MongoMapper: