Databases Reference
In-Depth Information
MongoDB is a document store that can persist arbitrary collections of data as
long as it can be represented using a JSON-like object hierarchy. (If you aren't
familiar with JSON, read about the specifi cation at www.json.org/ . It's a fast,
lightweight, and popular data interchange format for web applications.) To
present a fl avor of the JSON format, a log fi le element extracted from the access
log can be represented as follows:
{
“ApacheLogRecord”: {
“ip”: “127.0.0.1”,
“ident” : “-”,
“http_user” : “frank”,
“time” : “10/Oct/2000:13:55:36 -0700”,
“request_line” : {
“http_method” : “GET”,
“url” : “/apache_pb.gif”,
“http_vers” : “HTTP/1.0”,
},
“http_response_code” : “200”,
“http_response_size” : “2326”,
“referrer” : “http://www.example.com/start.html”,
“user_agent” : “Mozilla/4.08 [en] (Win98; I ;Nav)”,
},
}
The corresponding line in the log fi le is as follows:
127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700]
“GET /apache_pb.gif HTTP/1.0” 200
2326 ”http://www.example.com/start.html” ”Mozilla/4.08 [en]
(Win98; I ;Nav)”
MongoDB supports all JSON data types, namely, string, integer, boolean, double,
null, array, and object. It also supports a few additional data types. These
additional data types are date, object id, binary data, regular expression, and code.
Mongo supports these additional data types because it supports BSON, a binary
encoded serialization of JSON-like structures, and not just plain vanilla JSON.
You can learn about the BSON specifi cation at http://bsonspec.org/ .
To insert the JSON-like document for the line in the log fi le into a collection
named logdata , you could do the following in the Mongo shell:
doc = {
“ApacheLogRecord”: {
“ip”: “127.0.0.1”,
“ident” : “-”,
“http_user” : “frank”,
“time” : “10/Oct/2000:13:55:36 -0700”,
“request_line” : {
“http_method” : “GET”,
continues
Search WWH ::




Custom Search