mongodb

How to page embedded documents in mongo

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 ...

When should I use a NoSQL database (like MongoDB or CouchDB) instead of a relational database? Is it okay to use both on the same site?

What are the advantages of using NoSQL databases? I've read a lot about them lately, but I'm still unsure why I would want to implement one, and under what circumstances I would want to use one. ...

How to avoid the same record inserted twice in MongoDB (using Mongoid) or ActiveRecord (Rails using MySQL)?

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...

Mongoid Object.all seems to return a lot of []

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 => [] ...

MongoDB assumes 64 bit system - does it mean the hardware or the OS kernel or both?

This post says that you need a 64 bit system for MongoDB if your data is bigger than 2GB. In my local machine, a 64 bit Intel C2D running 32 bit Mac OS X Leopard, the MongoDB 64 bit version runs without any error. On the server, a 64 bit machine running 32 bit CentOS 5.0, the 64 bit MongoDB won't run. 32 bit runs OK. My question is, d...

How would you implement these queries efficiently in MongoDB?

Links have one or more tags, so at first it might seem natural to embed the tags: link = { title: 'How would you implement these queries efficiently in MongoDB?' url: 'http://stackoverflow.com/questions/3720972' tags: ['ruby', 'mongodb', 'database-schema', 'database-design', 'nosql']} How would these queries be imple...

Mongoid on Rails won't take SomeClass.where({:some_date.gte => '2010-09-01'}) if some_date is DateTime but needs to be Time class?

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....

How do I diagnose connection problems with MongoDB

Using the c# driver and MongoDB on windows server. Connection code looks like this: using (var mongo = new Mongo(ConnectionString)) { mongo.Connect(); //do stuff mongo.Disconnect(); } if ConnectionString == "mongodb://LocalHost/MyCollection" everything is fine if ConnectionString == anything else... doesn't work.....

How does MongoDB compares the date only and ignores the time, such as date <= '2010-09-10' ?

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...

Does Mongoid have Map/Reduce?

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...

Why MongoDB can create unique index but Mongoid cannot?

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...

How to use MongoDB Ruby Driver to do a "Group" (group by)?

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...

java types in org.bson.BSONObject

Hi all, I'm currently learning the BSON java library for mongodb and I'm trying to transform a org.bson.BSONObject into XML in order to transform it with a XSLT stylesheet. What kind of java types can I find as values in a BSONObject from a Mongodb ? Of course there will be: BSONObject (internal doc) java.lang.String ??? what are ...

Which database for chat logging?

I'm implementing a chat system. What kind of database I should use for logging chat messages? I need to do some queries to it. For example "give me all the links from user x between these dates" I've heard some good things about MongoDB for this kind of stuff. How about other NoSQL solutions? Redis? Cassandra? How about old SQL solut...

Does MongoDB have automatic created & updated timestamps?

What's the best way to store timestamps in MongoDB? Which format is best: # "created": { "d" : "2010-03-29", "t" : "20:15:34" } # "created": "12343545234" # seconds since epoc # "created": "2010-03-14T21:20:14+0000" Is there a way to have MongoDB automatically set created and updated fields? Thanks! Matt ...

find_by_sql equivalent for mongoid?

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? ...

When NOT to use NoSQL?

There was an article on Hacker News a couple of days ago that reached first page titled something like "2 cases when not to use Mongodb" but I really can't find it anymore... Does anyone know where I can find the above described article? What cases are there when NoSQL fails? ...

Authentication for Rails 2.3.8 using MongoDB and mongo_mapper

Hi All, How will I do authentication using Rails 2.3.8 using MongoDB and mongo_mapper? Let me know your expert advise on this. By the way, a Rails noob here :) Thanks! ...

Does MongoDB's Map/Reduce always return results in floats?

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? ...

How to decide which NoSQL technology to use?

Hi, What is the pros and cons of MongoDB (document-based), HBase (column-based) and Neo4j (objects graph)? I'm particularly interested to know some of the typical use cases for each one. http://stackoverflow.com/questions/703999/what-are-some-examples-of-problems-that-are-best-solved-with-graphs Maybe any Slideshare or Scribd...