To introduce you to the various methods of accessing data, all the data used for examples in this chapter comes from the same data set. The data set is a collection that contains information about 5,000 words. This provides a large enough data set to implement the necessary examples.
You can create the data set on your development system by executing the ch15/generate_data.js script provided in the code archive for this book. The generate.js script is a basic JavaScript MongoDB shell script that will create a database named words and a collection named word_stats. To run the script, download the generate_data.js file from the book’s code archive to your local system, start MongoDB, and execute the following command from a console prompt in the same directory as the script file:
mongo generate_data.js
The structure of objects in this data set is as follows and should be fairly intuitive (which is why it was selected):
{
word: <word>,
first: <first_letter>,
last: <last_letter>,
size: <character_count>,
letters: [<array_of_characters_in_word_no_repeats>],
stats: {
vowels:<vowel_count>, consonants:<consonant_count>},
charsets: [
{
"type": <consonants_vowels_other>,
"chars": [<array_of_characters_of_type_in_word>]},
. . .
],
}
This document structure includes fields that are strings, integers, arrays, subdocuments, and arrays of subdocuments.