Hello
I have a projects model with just a name field and in it also the embedded relation to line_items.
class Project
include mongoid::document
field :name
embeds_many :line_items
end
class LineItem
include mongoid::document
field :title
embedded_in :project, :inverse_of => :line_items
en...
Lets say we have a posts collection, and embedded in posts is an array of comments.
How would I write a query to say, pull out only posts 11-20? A mongoid solution would be preferable, but a mongo query object would also be fine
...
For example, if we are doing Analytics recording the page_type, item_id, date, pageviews, timeOnPage.
It seems that they are several ways to avoid it. Is there an automatic way?
create index on the fields that uniquely identify the record, for example [page_type, item_id, date] and make the index unique, so that when adding the sam...
Why doesn't this work:
ruby-1.8.7-p249 > List.create :search_terms => 'foo'
=> #<List _id: 4c9044a02249c7a5e2000001, search_terms: "foo", user_id: nil>
ruby-1.8.7-p249 > List.all
=> #<Mongoid::Criteria:0x1030dea90 @klass=List, @documents=[], @selector={}, @options={}>
ruby-1.8.7-p249 > List.all.documents
=> []
...
It is strange that if in the model:
def SomeClass
some_date: Time
end
then
SomeClass.where({:some_date.gte => '2010-09-01'})
would work well, but when it is
def SomeClass
some_date: DateTime
end
(change Time to DateTime) then the query won't work? (will get 0 items back).
In the MongoDB shell, they both show up as
> db....
For some reason:
Analytic.where({:ga_date.gte => '2010-09-01'}).count() # greater than or equal to
gives back 0, but
Analytic.where({:ga_date.gte => Time.parse('2010-09-01')}).count()
gives back 230, which is the number of records (documents).
Actually, the first line on the top works in another case, so it is quite strange.
Ca...
I am using Ruby code to calculate sum from the array returned by Mongoid.
But maybe using Map/Reduce can be faster, except I don't see any docs for Map Reduce on mongoid.org and Google for
map reduce site:mongoid.org
doesn't give any result either. (or using MapReduce or Map/Reduce)
There are docs on MongoDB's site
map reduce site...
In the MongoDB shell, if I do the following, then an index is created, and also prevent duplicate records from being inserted:
db.analytics.ensureIndex({page: 1, some_id: 1, ga_date: -1}, {unique: true});
But I thought Mongoid can do the same:
http://mongoid.org/docs/indexing/
So I have:
class PageAnalytic < Analytic
include Mong...
related to http://stackoverflow.com/questions/2127374/mongodb-group-using-ruby-driver
if I want to do something like the following in SQL:
select page_id, count(page_id) from a_table group by page_id
I thought the MongoDB's doc says
http://api.mongodb.org/ruby/current/Mongo/Collection.html#group-instance_method
group(key, condition...
Is there some sort of find_by_sql equivalent for mongoid, where you pass a mongo query and it materializes Mongoid::Document s from the results?
...
I am using Mongoid, which is on top of the Ruby MongDB driver. Even though my Map's emit is giving out a parseInt(num), and the Reduce's return is giving back also a parseInt(num), the final results still are floats.
Is that particular to MongoDB? Any way to make it integer instead?
...
Hi, I'm looking for some recommendations on how to structure the tags part of this data model:
Here's a simplified version of it:
a Site has many Posts (relational association [references_many in mongoid speak]). A Site has a tree of tags
a Post has an array of tags (subset of the Site's tags, order doesn't matter)
The use cases I...
The following line works:
Analytic.collection.map_reduce(map, reduce).find
but is there a way to do
Analytic.collection.find('page_type' => 'products').map_reduce(map, reduce).find
and even filter a date range such as date >= "2010-08-01" and date <= "2010-08-31"?
...
If there is an index on
page_type, our_id, date
and when querying,
db.analytics.find({page_type: 'ingredients', ga_date:
{$gte : new Date('Wed Sep 08 2010 12:00:00 GMT-0800')}})
db.analytics.find({page_type: 'ingredients', ga_date:
{$gte : new Date('Wed Sep 08 2010 12:00:00 GMT-0800')}}).explain()
if our_id is omitted, or da...
If the following is used
Analytic.collection.map_reduce(map, reduce,
:query => {:page => subclass_name},
:sort => [[:pageviews, Mongo::DESCENDING]]).find.to_a
it won't sort by pageviews. Alternatively, if it is array of hash:
Analytic.collection.map_reduce(map, reduce,
:query => {:page => subclass_name},
:sort => [{:page...
Also known as the <<"User has many Databases" question.>>
The environment
My app is modeled like so:
user has_many databases
database has_many tables
table has_many rows
row habtm(+value) columns
you get the idea!
So instead of modelling a database inside a database,
I would like to have:
a sqlite3 database that h...
I googled and all others, but I didn't find the answer. The question is:
Hi, how can I do batch insert with Mongoid to MongoDB?
...
The idea is to do analytics of 30 or 2000 products out of a collection of 80,000 products.
Say, if there are 80,000 products, and to get the top products with highest number of pageviews in a category, which can include only 30 or up to 2000 products, so we can either filter out all those products first, and then use map/reduce to find ...
For example, when doing Analytics, there can be a map/reduce run that takes 10 seconds. After it is run, if other webpages can make use of that result, then it will be saving 10 seconds per page.
It will be good to have the map/reduce result cached somehow.
It is possible to record a sucessful map/reduce run as map_reduce_result_[time...
Hi guys,
Have somebody tried to rewrite CanCan ActiverRecordAddtions for
Mongoid http://github.com/ryanb/cancan/blob/master/lib/cancan/active_record_additions.rb
Regards,
Alexey Zakharov
...