{ "cells": [ { "cell_type": "markdown", "id": "5a16ab52-c7c4-45a0-bf18-e15fffad15f5", "metadata": { "tags": [] }, "source": [ "# Setup\n", "The following cells need to be run in order to use the Node kernel and import dependencies" ] }, { "cell_type": "code", "execution_count": null, "id": "2155ca2d-e582-4650-b9b8-c7deab90d9d4", "metadata": {}, "outputs": [], "source": [ "$$.config.awaitExecution = true;" ] }, { "cell_type": "markdown", "id": "60b11450-e7e4-4035-bc77-ba9629267ac0", "metadata": { "tags": [] }, "source": [ "## Import dependencies, Define cluster config" ] }, { "cell_type": "code", "execution_count": null, "id": "81bc67ab-2ec9-459f-8a5e-e5bcacca8e71", "metadata": {}, "outputs": [], "source": [ "require(\"child_process\").execSync(\"asd\");\n", "const Aerospike = require('aerospike');\n", "const wine = require('./wine-data.json');\n", "const exp = Aerospike.exp;\n", "const op = Aerospike.operations;\n", "const map = Aerospike.maps;\n", "\n", "// Define cluster config\n", "const config = {\n", " hosts: '127.0.0.1:3000'\n", "}\n", "\n", "console.log('Ready to go!');" ] }, { "cell_type": "markdown", "id": "0d2b59f5-0f83-437d-8827-0686ef1fe358", "metadata": { "tags": [] }, "source": [ "# JSON Document" ] }, { "cell_type": "markdown", "id": "6294b386-aaf2-497c-9a4e-a8b8f7049e61", "metadata": { "tags": [] }, "source": [ "## Document Format" ] }, { "cell_type": "markdown", "id": "4149a5d2-3d6c-4bc0-8094-1cea09f2982d", "metadata": { "tags": [] }, "source": [ "The document is an array of objects like the example below:\n", "\n", "```json\n", "{\n", " points:\"87\",\n", " title:\"Nicosia 2013 Vulkà Bianco (Etna)\",\n", " description:\"Aromas include tropical fruit, broom, brimstone and dried herb. The palate isn't overly expressive, offering unripened apple, citrus and dried sage alongside brisk acidity.\",\n", " taster: {\n", " name:\"Kerin O’Keefe\",\n", " twitter_handle:\"@kerinokeefe\"\n", " },\n", " price:null,\n", " designation:\"Vulkà Bianco\",\n", " variety:\"White Blend\",\n", " regions: {\n", " primary: \"Etna\",\n", " secondary: null\n", " },\n", " province:\"Sicily & Sardinia\",\n", " country:\"Italy\",\n", " winery:\"Nicosia\"\n", "}\n", "```" ] }, { "cell_type": "markdown", "id": "d92a67ec-8f5a-4c1a-8031-1064a876fb3a", "metadata": { "tags": [] }, "source": [ "# Write Data" ] }, { "cell_type": "markdown", "id": "8ffede46-cbe0-4857-b3bc-5a1c40065a9a", "metadata": {}, "source": [ "The following code will create a record for each wine review in the data set." ] }, { "cell_type": "code", "execution_count": null, "id": "363ea39d-435f-448a-abb6-ddf768faf85b", "metadata": {}, "outputs": [], "source": [ "const writeRecords = async () => {\n", " let client = await Aerospike.connect(config);\n", " console.log('Writing records...');\n", " \n", " return new Promise( async (resolve, reject) => {\n", " // Create write policy\n", " writePolicy = new Aerospike.WritePolicy({\n", " key: Aerospike.policy.key.SEND\n", " });\n", "\n", " // Loop through wines and write records\n", " try{\n", " for(let i = 0; i < wine.length; i++){\n", " // Create key\n", " let key = new Aerospike.Key('demo', 'wine-node', i);\n", " // Write the record\n", " await client.put(key, wine[i], [], writePolicy);\n", " }\n", " }\n", " catch(err){\n", " console.log(err);\n", " reject();\n", " }\n", " \n", " // Get total objects in set\n", " let response = await client.infoAll('sets/demo/wine-node');\n", " console.log(response[0].info.split(':')[0]);\n", " console.log('Writing records complete');\n", " resolve(client);\n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "68ed2323-cd21-4ceb-af65-b0ae4ce7e7ea", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "937923d7-661e-4f20-b8d0-b01579632d04", "metadata": {}, "outputs": [], "source": [ "writeRecords().then((client) => client.close());" ] }, { "cell_type": "markdown", "id": "e7bd0373-a65a-4f36-95f2-a4de04798076", "metadata": { "tags": [] }, "source": [ "# Read Data" ] }, { "cell_type": "markdown", "id": "522b0b48-1552-4c39-9f2f-bd93fd9a11a1", "metadata": {}, "source": [ "### Read with a expression filter" ] }, { "cell_type": "code", "execution_count": null, "id": "f5db0bf3-7c1a-4ebc-ab3a-7298670d948d", "metadata": {}, "outputs": [], "source": [ "const queryFilter = async () => {\n", " let client = await Aerospike.connect(config);\n", " console.log('Reading with a filter expression...');\n", " \n", " return new Promise( async (resolve, reject) => {\n", " // Define query policy\n", " let queryPolicy = new Aerospike.QueryPolicy({\n", " filterExpression: exp.eq(\n", " exp.binStr('country'),\n", " exp.str('Georgia')\n", " )\n", " });\n", " // Create query\n", " let query = client.query('demo', 'wine-node');\n", " // Get query results\n", " let recordStream = await query.foreach(queryPolicy);\n", "\n", " // Iterate through the record stream\n", " recordStream.on('error', err => {\n", " console.log(err);\n", " reject();\n", " });\n", " recordStream.on('data', record => {\n", " console.log(record.bins);\n", " });\n", " recordStream.on('end', () => {\n", " console.log('End of records returned');\n", " resolve(client);\n", " });\n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "86cb20f0-e759-488e-9c18-c726cdd394b4", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "068fbee7-9fc3-4f22-a34a-1961856dda43", "metadata": {}, "outputs": [], "source": [ "queryFilter().then((client) => client.close());" ] }, { "cell_type": "markdown", "id": "89537317-5830-4618-9ce2-6022fd5de992", "metadata": { "tags": [] }, "source": [ "### Create Secondary indexes" ] }, { "cell_type": "markdown", "id": "6d5b6283-848f-4e9b-a4e5-ea2fd130ce41", "metadata": {}, "source": [ "#### String index\n", "Create a string index on the `country`." ] }, { "cell_type": "code", "execution_count": null, "id": "436dbc31-b788-44ea-bb53-876b75808349", "metadata": {}, "outputs": [], "source": [ "const country = async () => { \n", " let client = await Aerospike.connect(config);\n", " console.log('Creating country index...');\n", " \n", " return new Promise( async (resolve, reject) => {\n", " try{\n", " // Create country index\n", " let indexCountry = await client.createStringIndex({\n", " ns: 'demo', // namespace\n", " set: 'wine-node', // set name\n", " bin: 'country', // bin name\n", " index: 'country_idx', // index name\n", " });\n", "\n", " // Wait for the task to complete\n", " indexCountry.wait(1000, () => {\n", " console.log('Country index created');\n", " resolve(client);\n", " });\n", " }\n", " catch(err){\n", " console.log(err);\n", " reject();\n", " }\n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "7be371a5-d6d9-40f4-863f-ffb6eb946b7c", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "71c49b5e-d2eb-4679-899e-6c3ff71a9172", "metadata": {}, "outputs": [], "source": [ "country().then((client) => client.close());" ] }, { "cell_type": "markdown", "id": "3e713df9-eaf8-4f64-89d2-d4ae440fac69", "metadata": {}, "source": [ "#### Numeric index\n", "Create an numeric index on the `price`." ] }, { "cell_type": "code", "execution_count": null, "id": "6bfe6170-3f34-44ce-827f-e6cdb8552b48", "metadata": {}, "outputs": [], "source": [ "const price = async () => {\n", " let client = await Aerospike.connect(config);\n", " console.log('Creating price index...');\n", " \n", " return new Promise( async (resolve, reject) => {\n", " try{\n", " // Create price index\n", " let indexPrice = await client.createIntegerIndex({\n", " ns: 'demo', // namespace\n", " set: 'wine-node', // set name\n", " bin: 'price', // bin name\n", " index: 'price_idx', // index name\n", " });\n", "\n", " // Wait for the task to complete\n", " indexPrice.wait(1000, () => {\n", " console.log('Price index created\\n');\n", " resolve(client);\n", " });\n", " }\n", " catch(err){\n", " console.log(err);\n", " reject();\n", " }\n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "6d4fc836-bc8a-4454-9e2d-99c1603836af", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "02127693-baab-4ecf-83a7-fd51586c598b", "metadata": {}, "outputs": [], "source": [ "price().then((client) => client.close());" ] }, { "cell_type": "markdown", "id": "0edc0f2f-e2c0-4dd9-b8bd-0d4be0e2e7ce", "metadata": {}, "source": [ "#### Nested index\n", "Create a string index on the `name` key in the `taster` map. " ] }, { "cell_type": "code", "execution_count": null, "id": "f137ed59-7591-45f6-957a-b76555d11f15", "metadata": {}, "outputs": [], "source": [ "const taster = async () => {\n", " let client = await Aerospike.connect(config);\n", " console.log('Creating taster index...');\n", " \n", " return new Promise( async (resolve, reject) => {\n", " try{\n", " // Create taster name index\n", " let indexTaster = await client.createStringIndex({\n", " ns: 'demo', // namespace\n", " set: 'wine-node', // set name\n", " bin: 'taster', // bin name\n", " index: 'taster_idx', // index name\n", " type: Aerospike.indexType.MAPVALUES \n", " });\n", "\n", " // Wait for the task to complete\n", " indexTaster.wait(1000, () => {\n", " console.log('Taster index created');\n", " resolve(client);\n", " });\n", " }\n", " catch(err){\n", " console.log(err);\n", " reject();\n", " }\n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "e303ceac-61b0-47bd-949f-84c44186d723", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "af170638-b110-4b34-909e-c4919f4725e9", "metadata": {}, "outputs": [], "source": [ "taster().then((client) => client.close());" ] }, { "cell_type": "markdown", "id": "a3b11a92-c740-4262-8799-ab1116558faf", "metadata": { "tags": [] }, "source": [ "### Query data using a secondary index.\n", "Return all the wines from Georgia." ] }, { "cell_type": "code", "execution_count": null, "id": "21bd000e-38e4-4b61-9aff-1249933f40c2", "metadata": {}, "outputs": [], "source": [ "const querySindexString = async () => {\n", " let client = await Aerospike.connect(config);\n", " console.log('Reading with a string sindex filter...');\n", " \n", " return new Promise( async (resolve, reject) => {\n", " // Create query\n", " let query = client.query('demo', 'wine-node');\n", " // Set query sindex filter\n", " query.where(Aerospike.filter.equal('country', 'Georgia'));\n", " // Get query results\n", " let recordStream = await query.foreach();\n", "\n", " // Iterate through the record stream\n", " recordStream.on('error', err => {\n", " console.log(err);\n", " reject();\n", " });\n", " recordStream.on('data', record => {\n", " console.log(record.bins);\n", " });\n", " recordStream.on('end', () => {\n", " console.log('End of records returned \\n');\n", " resolve(client);\n", " });\n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "d9e99e9e-e0f4-4721-9662-ed559b4ce589", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "67b04772-ca13-4491-89ae-e728fb7a6096", "metadata": {}, "outputs": [], "source": [ "querySindexString().then((client) => client.close());" ] }, { "cell_type": "markdown", "id": "37d15f41-0484-47c7-a484-0cbd082782d9", "metadata": {}, "source": [ "Get all the with a price between 500 and 1000 USD." ] }, { "cell_type": "code", "execution_count": null, "id": "539eb52f-e302-4042-9b66-ea4d4240f69f", "metadata": {}, "outputs": [], "source": [ "const querySindexNumeric = async () => {\n", " let client = await Aerospike.connect(config);\n", " console.log('Reading with a numeric sindex filter...');\n", " \n", " return new Promise( async (resolve, reject) => {\n", " // Create query\n", " let query = client.query('demo', 'wine-node');\n", " // Set query sindex filter\n", " query.where(Aerospike.filter.range('price', 500, 1000));\n", " // Get query results\n", " let recordStream = await query.foreach();\n", "\n", " // Iterate through the record stream\n", " recordStream.on('error', err => {\n", " console.log(err);\n", " reject();\n", " });\n", " recordStream.on('data', record => {\n", " console.log(record.bins);\n", " });\n", " recordStream.on('end', () => {\n", " console.log('End of records returned \\n');\n", " resolve(client);\n", " });\n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "a996736a-dba2-47d5-92f6-6ce88366f3d2", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "0fedfc0c-5577-41f8-93fa-965b68a51d17", "metadata": {}, "outputs": [], "source": [ "querySindexNumeric().then((client) => client.close());" ] }, { "cell_type": "markdown", "id": "de68f6ef-8ded-4e7a-91a2-6b52c93f1ffb", "metadata": {}, "source": [ "### Query data with a secondary index and filter expression" ] }, { "cell_type": "markdown", "id": "9ce14439-3656-49e0-8f65-ee8cb0d7b568", "metadata": { "tags": [] }, "source": [ "Get all the wines from France with more than 95 points and price less than $70" ] }, { "cell_type": "code", "execution_count": null, "id": "e7f4a4c4-d502-4c57-aa3e-271bb68a941f", "metadata": {}, "outputs": [], "source": [ "const querySindexWithFilter = async () => {\n", " let client = await Aerospike.connect(config);\n", " console.log('Reading with a sindex and filter expression...');\n", "\n", " return new Promise( async (resolve, reject) => {\n", " // Define query policy\n", " let queryPolicy = new Aerospike.QueryPolicy({\n", " filterExpression: exp.and(\n", " exp.gt(exp.binInt('points'), exp.int(95)),\n", " exp.lt(exp.binInt('price'),exp.int(70))\n", " )\n", " });\n", " // Create query\n", " let query = client.query('demo', 'wine-node');\n", " // Set query sindex filter\n", " query.where(Aerospike.filter.equal('country', 'France'));\n", " // Get query results\n", " let recordStream = await query.foreach(queryPolicy);\n", "\n", " // Iterate through the record stream\n", " recordStream.on('error', err => {\n", " console.log(err);\n", " reject();\n", " });\n", " recordStream.on('data', record => {\n", " console.log(record.bins);\n", " });\n", " recordStream.on('end', () => {\n", " console.log('End of records returned \\n');\n", " resolve(client);\n", " });\n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "c5ecbb18-5df5-464b-8283-3d2ae9da341f", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "ec237046-d475-4728-a1c2-0e96075c6eb1", "metadata": {}, "outputs": [], "source": [ "querySindexWithFilter().then((client) => client.close());" ] }, { "cell_type": "markdown", "id": "b29fd191-660d-4ef8-a4b3-a1d0995b65bd", "metadata": { "tags": [] }, "source": [ "# Update Data" ] }, { "cell_type": "markdown", "id": "a43a9ce7-1844-409e-b90b-6a5e4a035053", "metadata": {}, "source": [ "## Create new wine object" ] }, { "cell_type": "code", "execution_count": null, "id": "296885f7-03eb-4ea7-9988-e2baa7ad5a8a", "metadata": {}, "outputs": [], "source": [ "const newWine = { \n", " \"points\": 85, \n", " \"title\": \"Barrel Racer 2013 Sauvignon Blanc (Solano County)\",\n", " \"description\": \"Practically a liquid fruit salad, this smells and tastes like orange, apple, cantaloupe and banana. The texture is smooth and rounded, rather than crisp. A little buttery flavor comes through on the finish.\", \n", " \"taster\": {\n", " \"name\":\"Jim Gordon\", \n", " \"twitter_handle\": \"@gordone_cellars\"\n", " }, \n", " \"price\": 18, \n", " \"designation\": null, \n", " \"variety\": \"Sauvignon Blanc\", \n", " \"regions\": {\n", " \"primary\": \"Solano County\", \n", " \"secondary\": \"North Coast\"\n", " },\n", " \"province\": \"California\",\n", " \"country\": \"US\", \n", " \"winery\": \"Barrel Racer\"\n", "}\n", "\n", "console.log('New wine created');" ] }, { "cell_type": "markdown", "id": "294c644f-5725-48f0-bd8c-ac3edc2d9171", "metadata": { "tags": [] }, "source": [ "### Update the collection with a new wine" ] }, { "cell_type": "code", "execution_count": null, "id": "2a80a21e-a614-4f8c-a359-974280ea978d", "metadata": {}, "outputs": [], "source": [ "const addNewWine = async () => { \n", " let client = await Aerospike.connect(config);\n", " console.log('Adding new wine...');\n", " \n", " return new Promise( async (resolve, reject) => {\n", " // Create write policy\n", " writePolicy = new Aerospike.WritePolicy({\n", " key: Aerospike.policy.key.SEND\n", " });\n", " // Create key\n", " let key = new Aerospike.Key('demo', 'wine-node', 10001);\n", " try{\n", " // Write record\n", " await client.put(key, newWine, [], writePolicy);\n", " }\n", " catch(err){\n", " console.log(err);\n", " reject();\n", " }\n", " \n", " // Verify record\n", " let record = await client.get(key);\n", " console.log(record.bins);\n", " console.log('New wine added \\n');\n", " resolve(client);\n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "b1c8e597-f695-4f5a-8a2a-3ca5d51b050c", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "0c36fa5e-c5a8-4fd0-adcf-32307f41447d", "metadata": {}, "outputs": [], "source": [ "addNewWine().then((client) => client.close());" ] }, { "cell_type": "markdown", "id": "e31dbf35-a683-437d-8bae-58c2e0c8aba9", "metadata": {}, "source": [ "### Update a wine within the collection" ] }, { "cell_type": "markdown", "id": "763aa669-df7f-4abd-8bd6-7cdb0f78f3ab", "metadata": {}, "source": [ "Update the price of a wine." ] }, { "cell_type": "code", "execution_count": null, "id": "cb40aada-d9dd-425c-9e7b-2f005626f7f0", "metadata": {}, "outputs": [], "source": [ "const updateWine = async () => {\n", " let client = await Aerospike.connect(config);\n", " console.log('Updating wine price...');\n", " \n", " return new Promise( async (resolve, reject) => {\n", " // Create key\n", " let key = new Aerospike.Key('demo', 'wine-node', 10001);\n", " try{\n", " // Write record\n", " await client.put(key, {price: 24}, [], writePolicy);\n", " }\n", " catch(err){ \n", " console.log(err);\n", " reject();\n", " }\n", " \n", " // Verify update\n", " let record = await client.select(key, ['price']);\n", " console.log(record.bins);\n", " console.log('Wine price updated \\n');\n", " resolve(client);\n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "9564e75e-57dc-46c2-8777-8f4c05ad1609", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "8c685de1-5bba-4860-881c-508ee87e8336", "metadata": {}, "outputs": [], "source": [ "updateWine().then((client) => client.close());" ] }, { "cell_type": "markdown", "id": "435d0e02-52b8-4b75-a424-aad4260ceee5", "metadata": {}, "source": [ "### Update all instances of a nested value in the collection" ] }, { "cell_type": "markdown", "id": "c108ed2d-edb6-40aa-88f1-c7ba06071d24", "metadata": {}, "source": [ "Update the twitter handle for Lauren Buzzeo on every wine they have tasted." ] }, { "cell_type": "code", "execution_count": null, "id": "43b9fe0d-259e-4591-b410-08fc2d500c59", "metadata": {}, "outputs": [], "source": [ "const updateTaster = async () => {\n", " let client = await Aerospike.connect(config);\n", " console.log('Updating Twitter handle...\\n');\n", " \n", " return new Promise( async (resolve, reject) => {\n", " // Define the operation\n", " let ops = [map.put('taster', 'twitter_handle', 'laurenbuzzed')]\n", " // Create query\n", " let query = client.query('demo', 'wine-node');\n", " // Set query sindex filter\n", " query.where(Aerospike.filter.contains('taster', 'Lauren Buzzeo', Aerospike.indexType.MAPVALUES));\n", " // Execute the query\n", " let updateJob = await query.operate(ops);\n", " \n", " // Wait for the job to complete\n", " updateJob.wait(1000, async () => {\n", " // Create the query\n", " let newQuery = client.query('demo', 'wine-node');\n", "\n", " // Set query bins and sindex filter\n", " newQuery.select('taster');\n", " newQuery.where(Aerospike.filter.contains('taster', 'Lauren Buzzeo', Aerospike.indexType.MAPVALUES));\n", "\n", " // Get query results\n", " let recordObj = await newQuery.results();\n", "\n", " for(let i = 0; i < 5; i++){\n", " console.log(recordObj[i].bins);\n", " }\n", " console.log('\\nTwitter handle updated');\n", " resolve(client);\n", " });\n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "2906a0bf-c583-4ac3-ad2b-60618a9d3952", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "b0616705-04e0-4354-94d2-28dd73dd6ea6", "metadata": {}, "outputs": [], "source": [ "updateTaster().then((client) => client.close());" ] }, { "cell_type": "markdown", "id": "a1f2c611-b8cd-4e64-868b-3b54c7cb301e", "metadata": { "tags": [] }, "source": [ "# Delete Data" ] }, { "cell_type": "markdown", "id": "373297eb-7aea-4bd7-8187-7ac747b8d20a", "metadata": {}, "source": [ "Delete all wines with a points vaule less than 81." ] }, { "cell_type": "code", "execution_count": null, "id": "337b4976-b034-4938-b6c6-34d4b1dc0d0d", "metadata": {}, "outputs": [], "source": [ "const removeWithFilter = async () => {\n", " let client = await Aerospike.connect(config);\n", " console.log('Deleting records...');\n", " \n", " return new Promise( async (resolve, reject) => {\n", " let queryPolicy = new Aerospike.QueryPolicy({\n", " filterExpression: exp.lt(\n", " exp.binInt('points'),\n", " exp.int(81)\n", " )\n", " });\n", " \n", " // Create query\n", " let query = client.query('demo', 'wine-node');\n", " // Create ops\n", " let ops = [op.delete()];\n", " \n", " // Execute the query\n", " let removeJob = await query.operate(ops, queryPolicy); \n", " // Wait for the job to complete\n", " removeJob.wait(1000, async () => {\n", " console.log('Checking records...');\n", "\n", " // Check for deleted records\n", " let newQuery = client.query('demo', 'wine-node');\n", " let recordObj = await newQuery.results(queryPolicy);\n", "\n", " if(recordObj.length > 0){\n", " console.log('Records exist');\n", " }\n", " else{\n", " console.log('Records deleted');\n", " resolve(client);\n", " }\n", " }); \n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "9a4672ae-ab91-4a81-94cb-9a3fa9cbd5e5", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "203b0e03-e4de-4a5d-a770-f3a1bdd54565", "metadata": {}, "outputs": [], "source": [ "removeWithFilter().then((client) => client.close());" ] }, { "cell_type": "markdown", "id": "a51030b5-9271-402e-be7e-13d4b184f3a0", "metadata": {}, "source": [ "## Cleanup" ] }, { "cell_type": "code", "execution_count": null, "id": "5fa02b14-2293-4ae7-b906-fb88852c1de8", "metadata": {}, "outputs": [], "source": [ "const cleanup = async () => {\n", " let client = await Aerospike.connect(config);\n", " console.log('Cleaning up...');\n", " return new Promise( async (resolve, reject) => {\n", " try{\n", " // Remove data\n", " await client.truncate('demo', 'wine-node', 0);\n", " console.log('Data removed');\n", "\n", " // Remove indexes\n", " await client.indexRemove('demo', 'country_idx');\n", " console.log('Country index removed');\n", " \n", " await client.indexRemove('demo', 'price_idx');\n", " console.log('Price index removed');\n", " \n", " await client.indexRemove('demo', 'taster_idx');\n", " console.log('Taster index removed');\n", " resolve(client);\n", " }\n", " catch(err){\n", " console.log(err);\n", " reject();\n", " }\n", " });\n", "}" ] }, { "cell_type": "markdown", "id": "00b68fb1-b2cd-49f6-85e2-29986447b4cf", "metadata": {}, "source": [ "Run the function" ] }, { "cell_type": "code", "execution_count": null, "id": "1534c774-1cad-4beb-9f24-ea6166180add", "metadata": {}, "outputs": [], "source": [ "cleanup().then((client) => client.close());" ] } ], "metadata": { "kernelspec": { "display_name": "JavaScript (Node.js)", "language": "javascript", "name": "javascript" }, "language_info": { "file_extension": ".js", "mimetype": "application/javascript", "name": "javascript", "version": "16.18.1" } }, "nbformat": 4, "nbformat_minor": 5 }