|
36 | 36 | "id": "dfc73c1e-9918-4d0a-ab22-4187a9c47678",
|
37 | 37 | "metadata": {},
|
38 | 38 | "source": [
|
39 |
| - "<img src=https://raw.githubusercontent.com/singlestore-labs/spaces-notebooks/master/notebooks/atlas-and-kai/images/mongo-db-singlestoredb.png width=\"100%\">" |
| 39 | + "<img src=https://raw.githubusercontent.com/singlestore-labs/spaces-notebooks/master/notebooks/atlas-and-kai/images/mongo-db-singlestoredb.png width=\"100%\">\n", |
| 40 | + "\n", |
| 41 | + "The data set used in this competition/demo contains some E-commerce data revolving around customers and products that they have purchased. In this notebook, we will run a few queries using SingleStore Kai which will allow us to migrate MongoDB data and run MongoDB queries directly through SingleStore. To create your entry for the raffle, please open and complete the following form: https://forms.gle/n8KjTpJgPL29wFHV9\n", |
| 42 | + "\n", |
| 43 | + "If you have any issues while completing the form, please reach out to a SingleStore team member at the event." |
40 | 44 | ]
|
41 | 45 | },
|
42 | 46 | {
|
|
45 | 49 | "id": "1c7f4c37-2c1d-4507-9564-de2bea190005",
|
46 | 50 | "metadata": {},
|
47 | 51 | "source": [
|
48 |
| - "## Install libraries and import modules" |
| 52 | + "## Install libraries and import modules\n", |
| 53 | + "\n", |
| 54 | + "First, we will need to import the necessary dependencies into our notebook environment. This includes some python libraries needed to run our queries." |
49 | 55 | ]
|
50 | 56 | },
|
51 | 57 | {
|
|
58 | 64 | "!pip install pymongo pandas ipywidgets --quiet"
|
59 | 65 | ]
|
60 | 66 | },
|
| 67 | + { |
| 68 | + "attachments": {}, |
| 69 | + "cell_type": "markdown", |
| 70 | + "id": "58c2085f-d9f4-4faa-b787-2e0cf952d0b1", |
| 71 | + "metadata": {}, |
| 72 | + "source": [ |
| 73 | + "To ensure that we have a database we can use, we will then make sure that a database exists. If it doesn't we will have the notebook create one for us." |
| 74 | + ] |
| 75 | + }, |
61 | 76 | {
|
62 | 77 | "cell_type": "code",
|
63 | 78 | "execution_count": 2,
|
|
75 | 90 | " %sql CREATE DATABASE {{database_to_use}}"
|
76 | 91 | ]
|
77 | 92 | },
|
| 93 | + { |
| 94 | + "attachments": {}, |
| 95 | + "cell_type": "markdown", |
| 96 | + "id": "033b3e8b-d445-41de-b682-77d66f98aed8", |
| 97 | + "metadata": {}, |
| 98 | + "source": [ |
| 99 | + "Next, let's run the code that will actually import the needed dependencies, including `pymongo`, that will be used to connect to SingleStore and our Mongo instance where the initial data is stored." |
| 100 | + ] |
| 101 | + }, |
78 | 102 | {
|
79 | 103 | "cell_type": "code",
|
80 | 104 | "execution_count": 3,
|
|
97 | 121 | "metadata": {},
|
98 | 122 | "source": [
|
99 | 123 | "## Connect to Atlas and SingleStore Kai endpoints\n",
|
100 |
| - "We are using a shared tier on the backend for Atlas" |
| 124 | + "\n", |
| 125 | + "Next, we will connect to the MongoDB Atlas instance using a Mongo client. We will need to connect to this instance to get our initial data, currently stored in Mongo." |
101 | 126 | ]
|
102 | 127 | },
|
103 | 128 | {
|
|
115 | 140 | "mongotxs = mydbmongodb[\"txs\"]"
|
116 | 141 | ]
|
117 | 142 | },
|
| 143 | + { |
| 144 | + "attachments": {}, |
| 145 | + "cell_type": "markdown", |
| 146 | + "id": "52c51825-19ac-4512-87b5-619fb0b48a67", |
| 147 | + "metadata": {}, |
| 148 | + "source": [ |
| 149 | + "Then, we will need to connect to the SingleStore Kai API which will allow us to import and access the Mongo data we will move over from Mongo Atlas." |
| 150 | + ] |
| 151 | + }, |
118 | 152 | {
|
119 | 153 | "cell_type": "code",
|
120 | 154 | "execution_count": 5,
|
121 | 155 | "id": "20e25f4a-a6ce-4e3a-80c5-c56002945c7e",
|
122 | 156 | "metadata": {},
|
123 | 157 | "outputs": [],
|
124 | 158 | "source": [
|
| 159 | + "db_to_use = database_to_use\n", |
125 | 160 | "s2clientmongodb = pymongo.MongoClient(connection_url_kai)\n",
|
126 |
| - "s2dbmongodb = s2clientmongodb[database_to_use]\n", |
| 161 | + "s2dbmongodb = s2clientmongodb[db_to_use]\n", |
127 | 162 | "s2mongoitems = s2dbmongodb[\"items\"]\n",
|
128 | 163 | "s2mongocusts = s2dbmongodb[\"custs\"]\n",
|
129 | 164 | "s2mongotxs = s2dbmongodb[\"txs\"]"
|
|
135 | 170 | "id": "36c6162c-e0a2-404b-8d9f-9af8df8b8cea",
|
136 | 171 | "metadata": {},
|
137 | 172 | "source": [
|
138 |
| - "## Copy Atlas collections into SingleStore Kai" |
| 173 | + "## Copy Atlas collections into SingleStore Kai\n", |
| 174 | + "\n", |
| 175 | + "As our next step, we need to get our MongoDB data hosted in Atlas over to SingleStore. For this, we will run the following code that will then replicate the selected Mongo collections into our SingleStore instance. This will make the MongoDB data available in SingleStore, allowing us to migrate away from MongoDB and to perform all of our data storage and queries in a single database instead of having multiple data silos." |
139 | 176 | ]
|
140 | 177 | },
|
141 | 178 | {
|
|
160 | 197 | "id": "ca4dbc9b-f96a-46c1-a4ac-aa761e0d19ec",
|
161 | 198 | "metadata": {},
|
162 | 199 | "source": [
|
163 |
| - "## Total quantity of products sold across all products" |
| 200 | + "## QUERY 1: Total quantity of products sold across all products\n", |
| 201 | + "\n", |
| 202 | + "Our first query on the newly migrated data will be to retrieve the total quanitity of products across every product within our dataset. As you'll see, even though we are running in SingleStore, we can still use Mongo query syntax using SingleStore Kai." |
164 | 203 | ]
|
165 | 204 | },
|
166 | 205 | {
|
|
193 | 232 | "print(\"Total Product Quantity Sold is\",total_quantity)"
|
194 | 233 | ]
|
195 | 234 | },
|
| 235 | + { |
| 236 | + "attachments": {}, |
| 237 | + "cell_type": "markdown", |
| 238 | + "id": "17c39c6d-5f5c-4712-86d4-57ab70f185ed", |
| 239 | + "metadata": {}, |
| 240 | + "source": [ |
| 241 | + "#### ACTION ITEM!\n", |
| 242 | + "Take the output from this query and put it into the **ANSWER NUMBER 1** field in the Google Form." |
| 243 | + ] |
| 244 | + }, |
196 | 245 | {
|
197 | 246 | "attachments": {},
|
198 | 247 | "cell_type": "markdown",
|
199 | 248 | "id": "58f643e0-0205-4cf7-97de-dcd93bef0a64",
|
200 | 249 | "metadata": {},
|
201 | 250 | "source": [
|
202 |
| - "## Top selling Product" |
| 251 | + "## QUERY 2: Top selling Product\n", |
| 252 | + "\n", |
| 253 | + "Our next query will be to find the top selling product within our data. Once again, we are issuing a Mongo query against our SingleStore instance. If we had an application integrated with MongoDB but wanted to migrate to SingleStore, we could do so without having to rewrite the queries within our application!" |
203 | 254 | ]
|
204 | 255 | },
|
205 | 256 | {
|
|
235 | 286 | ]
|
236 | 287 | },
|
237 | 288 | {
|
| 289 | + "attachments": {}, |
| 290 | + "cell_type": "markdown", |
| 291 | + "id": "7efdb5cb-502f-46e0-9464-a62ab60beace", |
| 292 | + "metadata": {}, |
| 293 | + "source": [ |
| 294 | + "### ACTION ITEM!\n", |
| 295 | + "Take the output from this query and put it into the **ANSWER NUMBER 2** field in the Google Form." |
| 296 | + ] |
| 297 | + }, |
| 298 | + { |
| 299 | + "attachments": {}, |
238 | 300 | "cell_type": "markdown",
|
239 | 301 | "id": "e45de51e-f54b-4788-8fb3-2aadc9143533",
|
240 | 302 | "metadata": {},
|
241 | 303 | "source": [
|
242 |
| - "## Top selling Location" |
| 304 | + "## QUERY 3: Top selling Location" |
243 | 305 | ]
|
244 | 306 | },
|
245 | 307 | {
|
|
290 | 352 | ]
|
291 | 353 | },
|
292 | 354 | {
|
| 355 | + "attachments": {}, |
| 356 | + "cell_type": "markdown", |
| 357 | + "id": "153c9dd5-1804-42c6-b55e-ce043ee07a84", |
| 358 | + "metadata": {}, |
| 359 | + "source": [ |
| 360 | + "### ACTION ITEM!\n", |
| 361 | + "Take the output from this query and put it into the **ANSWER NUMBER 3** field in the Google Form." |
| 362 | + ] |
| 363 | + }, |
| 364 | + { |
| 365 | + "attachments": {}, |
293 | 366 | "cell_type": "markdown",
|
294 | 367 | "id": "93934fde-c22e-4bda-992f-ed01dc83283c",
|
295 | 368 | "metadata": {},
|
296 | 369 | "source": [
|
297 |
| - "## Clean up" |
| 370 | + "## Clean up and submit!\n", |
| 371 | + "\n", |
| 372 | + "**Make sure to click submit on your Google Form to make sure you've been entered into the SingleStore NOW 2024 raffle!**\n", |
| 373 | + "\n", |
| 374 | + "Additionally, if you'd like to clean up your instance, you can run the statement below. To learn more about SingleStore, please connect with one of our SingleStore reps here at the conference!" |
298 | 375 | ]
|
299 | 376 | },
|
300 | 377 | {
|
| 378 | + "attachments": {}, |
301 | 379 | "cell_type": "markdown",
|
302 | 380 | "id": "599ca6e3-3847-467a-8a33-8f91e52a9cd1",
|
303 | 381 | "metadata": {},
|
|
325 | 403 | },
|
326 | 404 | {
|
327 | 405 | "cell_type": "markdown",
|
328 |
| - "id": "9635adf8-8137-4637-b94d-22835ba8112d", |
| 406 | + "id": "760cef98-671d-4754-bab4-67dc6f38c209", |
329 | 407 | "metadata": {},
|
330 | 408 | "source": [
|
331 | 409 | "<div id=\"singlestore-footer\" style=\"background-color: rgba(194, 193, 199, 0.25); height:2px; margin-bottom:10px\"></div>\n",
|
|
0 commit comments