mongoid

See existing indexes in MongoDB using mongoid

我只是一个虾纸丫 提交于 2019-12-18 12:24:05
问题 I'd like to see the existing indexes used by MongoDB. Can I do the equivalent of $ mongod > use my_db > db.system.indexes.find() using Mongoid? $ rails console > ? Would be convenient from my heroku apps using MongoHQ. Thanks! 回答1: You can get at the underlying indexes for a Mongoid model through its collection . > YourModel.collection.indexes This reaches down into the moped driver (in Mongoid 3). See http://mongoid.org/en/moped/docs/driver.html 来源: https://stackoverflow.com/questions

Querying embedded objects in Mongoid/rails 3 (“Lower than”, Min operators and sorting)

时间秒杀一切 提交于 2019-12-18 10:59:43
问题 I am using rails 3 with mongoid. I have a collection of Stocks with an embedded collection of Prices : class Stock include Mongoid::Document field :name, :type => String field :code, :type => Integer embeds_many :prices class Price include Mongoid::Document field :date, :type => DateTime field :value, :type => Float embedded_in :stock, :inverse_of => :prices I would like to get the stocks whose the minimum price since a given date is lower than a given price p, and then be able to sort the

How to use mongoDB with Solr?

天大地大妈咪最大 提交于 2019-12-18 10:57:31
问题 Is it possible to replicate data from mongoDB to Solr? I'm using ruby + sinatra + mongoid. Or i need to make hooks with after_create, after_update and so on through rsolr? 回答1: 10gen introduced Mongo Connector, which allows to push data into Solr (among others) http://blog.mongodb.org/post/29127828146/introducing-mongo-connector From their example: python mongo_connector.py -m localhost:27217 -t http://localhost:8080/solr 回答2: Some people integrated Solr with MongoDB with application code

HABTM mongoid following/follower

…衆ロ難τιáo~ 提交于 2019-12-18 10:57:20
问题 Mongoid ships with .push on a habtm, which sets a habtm relationship in both directions. Although delete will #delete an associated record, there's no documented way to delete only a relationship that I have seen. Is there a better way of doing this? Is there a better way of ensuring uniqueness? has_and_belongs_to_many :following, {class_name: 'User', inverse_of: :followers, inverse_class_name: 'User'} has_and_belongs_to_many :followers, {class_name: 'User', inverse_of: :following, inverse

How to query MongoDB directly from Ruby instead of using Mongoid?

折月煮酒 提交于 2019-12-18 10:43:00
问题 I am writing a migration for a Rails application that uses MongoDB and Mongoid. My migration currently uses my models that use Mongoid to query and update records, but the performance is sub-par. I am essentially updating all records in a large collection and making n+20 queries. I killed the migration after taking an hour to run locally (and didn't finish). I would like to be able to run raw queries to mongo without too much effort. I'm assuming there is some way to access a mongo driver

How to query MongoDB directly from Ruby instead of using Mongoid?

一个人想着一个人 提交于 2019-12-18 10:42:48
问题 I am writing a migration for a Rails application that uses MongoDB and Mongoid. My migration currently uses my models that use Mongoid to query and update records, but the performance is sub-par. I am essentially updating all records in a large collection and making n+20 queries. I killed the migration after taking an hour to run locally (and didn't finish). I would like to be able to run raw queries to mongo without too much effort. I'm assuming there is some way to access a mongo driver

Is it a good idea to generate per day collections in mongodb

给你一囗甜甜゛ 提交于 2019-12-18 06:46:54
问题 Is it a good idea to create per day collections for data on a given day (we could start with per day and then move to per hour if there is too much data). Is there a limit on the number of collections we can create in mongodb, or does it result in performance loss (is it an overhead for mongodb to maintain so many collections). Does a large number of collections have any adverse effect on performance? To give you more context, the data will be more like facebook feeds, and only the latest

Mongo query using mongoid in rails app causing cursor timeout error

点点圈 提交于 2019-12-18 03:22:31
问题 I have a mongo query in my rails app that is timing out because the collection is huge. FbCheckin.where(ext_fb_place_id: self.ext_fb_place_id).all I've read from documentation that you can add a timeout option to prevent the cursor from timing out with the following message: Moped::Errors::CursorNotFound: The operation: "GET MORE" failed with error I've tried several ways including FbCheckin.where(ext_fb_place_id: ext_fb_place_id, {:timeout=>false}).all and FbCheckin.find(ext_fb_place_id: ext

Creating short, unique object id's in MongoDB

我们两清 提交于 2019-12-17 23:19:03
问题 I'm making an app similar to instagram using Rails/Mongoid. I want a unique ID that I can use in a url like http://instagr.am/p/DJmU8/ What's the easiest way to do that? Can I derive such an ID from the default BSON ObjectID Mongo creates? 回答1: You may try to use first 4 bytes of ObjectID (they will represent timestamp). But, to be 100% safe, it's better to produce really unique short id, by implementing a counter. You can use separate collection to maintain current value of your counter.

Rails 3: how to use active record and mongoid at the same time

[亡魂溺海] 提交于 2019-12-17 22:44:07
问题 I read alot that folks recommend using nosql together with sql datastores. For example have some reporting audit-trailing or log information in mysql and some threaded hierarchical data in mongodb. Is it possible to hook up rails with active record on mysql as well as mongoid? Out of the box it seems not to work...Any hints? Or is this a not recommended approach? 回答1: Well, to do it, you're supposed to leave Rails intact, so don't exclude libraries like it's commonly suggested in Mongoid