Browsing the archives for the Querying category

Quick Tip: $size things up to $type

in Querying, Quick Tip

TweetThere are a number of quarky little MongoDB commands and queries hidden in the docs, two of them are $size and $type. Does it really matter? $size that is … The $size operator matches any array with the specified number of elements. The basic use would be something like … > db.ideas.find( { votes : { $size: 2 } [...]

0 Comments

Easily Move Documents Between Collections or Databases

in Administration, Querying

TweetDoes this senario sound familiar? The good news: your new super amazing mashup is becoming super popular, its getting featured on tech blogs and podcasts w00t! You’ve used MongoDB for your database backed and so things have been scaling pretty well, and your analytics you have been tracking are really adding up, like millions and millions [...]

1 Comment

Quick Tip: How to $size up a MongoDB Array

in Querying, Quick Tip

TweetSince MongoDB will allow you to store more than just string and int values but also things like arrays … from time to time you might need to know how many items are in an array in your document. For example, say you have a hosting business and to make a good profit you need [...]

0 Comments

Quick Tip: MongoDB Distinct Count

in Querying, Quick Tip

TweetOne query SQL users are pretty used to writing is DISTINCT with COUNT() to get the number if distinct (unique) rows that match a statement like … SELECT COUNT(DISTINCT(PageURL)) FROM LogTable; This rather simple query will get us back the number of unique PageURL’s in our LogTable … not an amazingly useful query but you get [...]

10 Comments

Quick Tip: Return Only 1 Field

in Querying, Quick Tip

TweetSay you have a log of hits to your podcast, something like … { “_id” : ObjectId(“4c6c753800ae261d80000009″), “podcastID” : 1, “remoteUserIP” : “10.40.52.55″, “remoteUserSession” : “gpn1vz1crveoqtgtlbh1tgd1″, “remoteUserAgent” : “iTunes/9.2.1 (Macintosh; Intel Mac OS X 10.6.4) AppleWebKit/533.17.8″, “created” : { “date” : “8/18/2010″, “time” : “5:05:12 PM” } } To get a quick snapshot of hits [...]

2 Comments