Database Reference
In-Depth Information
logging data in a database, as compared with the file system, provides easier organiza-
tion and much greater query power. Now, instead of using grep or a custom log search
utility, users can employ the MongoDB query language they know and love to examine
log output.
C ACHING
A data model that allows for a more holistic representation of objects, combined with
faster average query speeds, frequently allows MongoDB to be run in place of the more
traditional MySQL/memcached duo. For example, TBE, mentioned earlier, has been
able to dispense with memcached, serving page requests directly from MongoDB.
V ARIABLE SCHEMAS
Look at this code example: 12
curl https://stream.twitter.com/1/statuses/sample.json -umongodb:secret
| mongoimport -c tweets
Here you're pulling down a small sample of the Twitter stream and piping that
directly into a MongoDB collection. Since the stream produces JSON documents,
there's no need to munge the data before sending it to database. The mongoimport
tool directly translates the data to BSON . This means that each tweet is stored with its
structure intact, as a separate document in the collection. So you can immediately
operate on the data, whether you want to query, index, or perform a map-reduce
aggregation on it. And there's no need to declare the structure of the data in advance.
If your application needs to consume a JSON API , then having a system that so eas-
ily translates JSON is invaluable. If you can't possibly know the structure of your data
before you store it, then MongoDB's lack of schema constraints may greatly simply
your data model.
1.5
Tips and limitations
For all these good features, it's worth keeping in mind a system's trade-offs and limita-
tions. Some limitations should be noted before building a real-world application on
MongoDB and running in production. Most of these are consequences of MongoDB's
use of memory-mapped files.
First, MongoDB should usually be run on 64-bit machines. 32-bit systems are capa-
ble of addressing only 4 GB of memory. Acknowledging that typically half of this mem-
ory will be allocated by the operating system and program processes, this leaves just
2 GB of memory on which to map the data files. So if you're running 32-bit, and if you
have even a modest number of indexes defined, you'll be strictly limited to as little as
1.5 GB of data. Most production systems will require more than this, and so a 64-bit
system will be necessary. 13
12
This idea comes from http://mng.bz/52XI. I f you want to run this code, you'll need to replace
<code>-umongodb:secret</code> with your own Twitter username and password.
13
64-bit architectures can theoretically address up to 16 exabytes of memory, which is for all intents and pur-
poses unlimited.
Search WWH ::




Custom Search