mongomapper

Mongo find by regex: return only matching string

随声附和 提交于 2019-12-01 20:43:30
My application has the following stack: Sinatra on Ruby -> MongoMapper -> MongoDB The application puts several entries in the database. In order to crosslink to other pages, I've added some sort of syntax. e.g.: Coffee is a black, caffeinated liquid made from beans. {Tea} is made from leaves. Both drinks are sometimes enjoyed with {milk} In this example {Tea} will link to another DB entry about tea. I'm trying to query my mongoDB about all 'linked terms'. Usually in ruby I would do something like this: /{([a-zA-Z0-9])+}/ where the () will return a matched string. In mongo however I get the

Unset operation failing for MongoMapper model, cannot delete / remove key from model

亡梦爱人 提交于 2019-12-01 18:18:52
We're on mongodb 2.0.0, mongo gem 1.4.1, mongo_mapper 0.9.2, rails 3.0.6. We love MongoMapper, but we need helping resolving one nasty issue: we have a key carried over from some testing, but invoking obj.unset fails to do anything. Specifically, we are trying to remove an "id" key (not "_id") because it's causing MM to treat obj.id as different from obj._id, which we don't want. After clearing out the database, we ran these commands from a controller which does nothing else: (We also tried running the same code from the rails console, but it also fails.) logger.info "#{Game.keys.keys.inspect}

Upsert Multiple Records with MongoDb

一个人想着一个人 提交于 2019-11-30 20:48:20
I'm trying to get MongoDB to upsert multiple records with the following query, ultimately using MongoMapper and the Mongo ruby driver. db.foo.update({event_id: { $in: [1,2]}}, {$inc: {visit:1}}, true, true) This works fine if all the records exist, but does not create new records for records that do not exist. The following command has the desired effect from the shell, but is probably not ideal from the ruby driver. [1,2].forEach(function(id) {db.foo.update({event_id: id}, {$inc: {visit:1}}, true, true) }); I could loop through each id I want to insert from within ruby, but that would

How to configure MongoMapper and ActiveRecord in same Ruby Rails Project

房东的猫 提交于 2019-11-30 07:22:56
I've got an existing production Ruby/Rails app that I want to migrate to MongoDB over time, as time permits, because it's not an option to just rewrite it all at one time. I'd love to be able to just deprecate my old classes as I get to them. I plan to use MongoMapper. I can't find an example where anyone explains how to set up the database config files to allow connection to both data stores within one app. FWIW, I'm using Rails 3. I appreciate the help. Include your mongo_mapper gem in you Gemfile. Then in the models that you slowly want to start migrating over to MongoMapper, you just

Upsert Multiple Records with MongoDb

◇◆丶佛笑我妖孽 提交于 2019-11-30 05:37:01
问题 I'm trying to get MongoDB to upsert multiple records with the following query, ultimately using MongoMapper and the Mongo ruby driver. db.foo.update({event_id: { $in: [1,2]}}, {$inc: {visit:1}}, true, true) This works fine if all the records exist, but does not create new records for records that do not exist. The following command has the desired effect from the shell, but is probably not ideal from the ruby driver. [1,2].forEach(function(id) {db.foo.update({event_id: id}, {$inc: {visit:1}},

Mongoid or MongoMapper? [closed]

ε祈祈猫儿з 提交于 2019-11-29 20:01:09
I have tried MongoMapper and it is feature complete (offering almost all AR functionality) but i was not very happy with the performance when using large datasets. Has anyone compared with Mongoid? Any performance gains ? Aynat I have used MongoMapper for awhile but decided to migrate to MongoId. The reason is hidden issues plus arrogance towards users. I had to jump through hoops to make MongoMapper work with Cucumber (succeeded in the end) and to put a couple of patches even the project was simple, but it's not the point. When I tried to submit a bug fix (due to incompatibility with

Use Yaml for MongoMapper Config

岁酱吖の 提交于 2019-11-29 14:41:42
I have my Yaml configuration file, mongo.yml : development: adapter: mongodb database: fhsclock_development host: localhost port: nil test: adapter: mongodb database: fhsclock_test host: localhost port: nil production: adapter: mongodb database: fhsclock hosts: - - localhost - nil - - staff.mongohq.com - 10015 How do I use this file for configuration and connection with MongoMapper? MongoMapper will just use the file if it's you're using Rails and the file is at config/mongo.yml . If you're not on Rails, you can adapt this code from the source : config_file = Rails.root.join('config/mongo.yml'

How to configure MongoMapper and ActiveRecord in same Ruby Rails Project

谁都会走 提交于 2019-11-29 09:37:40
问题 I've got an existing production Ruby/Rails app that I want to migrate to MongoDB over time, as time permits, because it's not an option to just rewrite it all at one time. I'd love to be able to just deprecate my old classes as I get to them. I plan to use MongoMapper. I can't find an example where anyone explains how to set up the database config files to allow connection to both data stores within one app. FWIW, I'm using Rails 3. I appreciate the help. 回答1: Include your mongo_mapper gem in

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

不打扰是莪最后的温柔 提交于 2019-11-29 09:23:38
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 } Currently, the $slice operator is unavailable in the the $project operation, of the aggregation pipeline. So what you could do is, First $unwind , the my_field array, and then group them together and

Rails + MongoMapper + EmbeddedDocument form help

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 19:50:22
I am working on a pretty simple web application (famous last words) and am working with Rails 2.3.5 + MongoMapper 0.7.2 and using embedded documents. I have two questions to ask: First, are there any example applications out there using Rails + MongoMapper + EmbeddedDocument? Preferably on GitHub or some other similar site so that I can take a look at the source and see where I am supposed to head? If not ... ... what is the best way to approach this task? How would I go about creating a form to handle an embedded document. What I am attempting to do is add addresses to users. I can toss up