Databases Reference
In-Depth Information
“hbase”,
“memcached”,
“mongodb”,
“nosql”,
“redis”,
“web scale”
]
}
Now, you could easily create a multikey index on the tags fi eld as follows:
db.blogposts.ensureIndex({ tags:1 });
So far it's like any other index but next you could search by any one of the tag values like so:
db.blogposts.find({ tags:”nosql” });
This feature can be used to build out a complete keyword-based search. As with tags, you would need to
save the keywords in an array that could be saved as a value of a fi eld. The extraction of the keywords
itself is not done automatically by MongoDB. You need to build that part of the system yourself.
Maintaining a large array and querying through numerous documents that each hold a large array
could impose a performance drag on the database. To identify and preemptively correct some of the
slow queries you can leverage the MongoDB database profi ler. In fact, you can use the profi ler to log
all the operations.
The profi ler lets you defi ne three levels:
0 — Profi ler is off
1 — Slow operations (greater than 100 ms) are logged
2 — All operations are logged
To log all operations you can set the profi ler level to 2 like so:
db.setProfilingLevel(2);
The profi ler logs themselves are available as a MongoDB collection, which you can view using a
query as follows:
db.system.profile.find();
If you have been following along until now, you have theoretically learned almost everything there
is to learn about indexes and sorting in MongoDB. Next, you use the available tools to tune the
query to optimal performance as you access data from your collections.
INDEXING AND ORDERING IN COUCHDB
You have seen the RESTful query mechanisms in CouchDB. Now, you delve a bit into how the
values are indexed to make queries effi cient. Unlike MongoDB, the indexing features in CouchDB
Search WWH ::




Custom Search