Browsing the archives for the Quick Tip 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

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: Copy DBs Between Servers

in Administration, Quick Tip

TweetInspired by this Stackoverflow question I thought it would be worth while to post this quick tip … If you ever need to copy (or “clone”) a MongoDB databse between two MongoDB servers its as easy as running the copyDatabase() command. First, change into your admin db … Then, run copyDatabase() supplying the needed information, the [...]

5 Comments

Quick Tip: Using Users in MongoDB

in Administration, Quick Tip

TweetBy default a MongoDB install does not use a username/password combination to access the database. No Password, But Why? This is down to the design philosophy of MongoDB which is to push much of the “logic” to the application level and keep the database doing what databases do best! Hence,  given the way that MongoDB [...]

4 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