Fixed missing file contents
[tm351-mongo.git] / make-small-accidents.ipynb
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "import pymongo\n",
15 "client = pymongo.MongoClient('mongodb://ogedei:27017/')"
16 ],
17 "language": "python",
18 "metadata": {},
19 "outputs": [],
20 "prompt_number": 2
21 },
22 {
23 "cell_type": "markdown",
24 "metadata": {},
25 "source": [
26 "Connect to the `accidents` database"
27 ]
28 },
29 {
30 "cell_type": "code",
31 "collapsed": false,
32 "input": [
33 "db = client.accidents\n",
34 "accidents = db.accidents"
35 ],
36 "language": "python",
37 "metadata": {},
38 "outputs": [],
39 "prompt_number": 3
40 },
41 {
42 "cell_type": "code",
43 "collapsed": false,
44 "input": [
45 "accidents.find().count()"
46 ],
47 "language": "python",
48 "metadata": {},
49 "outputs": [
50 {
51 "metadata": {},
52 "output_type": "pyout",
53 "prompt_number": 4,
54 "text": [
55 "1355615"
56 ]
57 }
58 ],
59 "prompt_number": 4
60 },
61 {
62 "cell_type": "markdown",
63 "metadata": {},
64 "source": [
65 "Drop any existing small accident database"
66 ]
67 },
68 {
69 "cell_type": "code",
70 "collapsed": false,
71 "input": [
72 "client.drop_database('asmall')"
73 ],
74 "language": "python",
75 "metadata": {},
76 "outputs": [],
77 "prompt_number": 21
78 },
79 {
80 "cell_type": "markdown",
81 "metadata": {},
82 "source": [
83 "Create a new database with a new collection.\n",
84 "\n",
85 "Note that this is created lazily, so neither the database nor the collection will appear on the server until we've put some data in it."
86 ]
87 },
88 {
89 "cell_type": "code",
90 "collapsed": false,
91 "input": [
92 "small_db = client.asmall\n",
93 "small_accidents = small_db.accidents"
94 ],
95 "language": "python",
96 "metadata": {},
97 "outputs": [],
98 "prompt_number": 22
99 },
100 {
101 "cell_type": "markdown",
102 "metadata": {},
103 "source": [
104 "Copy the first 100 accidents across."
105 ]
106 },
107 {
108 "cell_type": "code",
109 "collapsed": false,
110 "input": [
111 "for a in accidents.find(limit=100):\n",
112 " small_accidents.insert(a)\n",
113 "small_accidents.find().count()"
114 ],
115 "language": "python",
116 "metadata": {},
117 "outputs": [
118 {
119 "metadata": {},
120 "output_type": "pyout",
121 "prompt_number": 23,
122 "text": [
123 "100"
124 ]
125 }
126 ],
127 "prompt_number": 23
128 },
129 {
130 "cell_type": "markdown",
131 "metadata": {},
132 "source": [
133 "Create the index for it."
134 ]
135 },
136 {
137 "cell_type": "code",
138 "collapsed": false,
139 "input": [
140 "small_accidents.create_index('Accident_Index')"
141 ],
142 "language": "python",
143 "metadata": {},
144 "outputs": [
145 {
146 "metadata": {},
147 "output_type": "pyout",
148 "prompt_number": 24,
149 "text": [
150 "'Accident_Index_1'"
151 ]
152 }
153 ],
154 "prompt_number": 24
155 },
156 {
157 "cell_type": "code",
158 "collapsed": false,
159 "input": [],
160 "language": "python",
161 "metadata": {},
162 "outputs": []
163 }
164 ],
165 "metadata": {}
166 }
167 ]
168 }