From c31dfa495715833f3f99df81eac1e6c08caf51c2 Mon Sep 17 00:00:00 2001
From: Marcus Schiesser <mail@marcusschiesser.de>
Date: Mon, 4 Dec 2023 11:29:46 +0700
Subject: [PATCH] fix: move mongodb to examples/

---
 apps/mongodb/CHANGELOG.md                     |  20 ---
 apps/mongodb/package.json                     |  17 ---
 .../mongodb => examples/data}/tinytweets.json | Bin
 {apps => examples}/mongodb/1_import.ts        |   2 +-
 .../mongodb/2_load_and_index.ts               |   0
 {apps => examples}/mongodb/3_query.ts         |   0
 {apps => examples}/mongodb/README.md          |  15 +--
 {apps => examples}/mongodb/docs/1_signup.png  | Bin
 .../mongodb/docs/2_connection_string.png      | Bin
 .../mongodb/docs/3_vectors_in_db.png          | Bin
 .../mongodb/docs/4_search_tab.png             | Bin
 .../mongodb/docs/5_json_editor.png            | Bin
 .../mongodb/docs/7_index_created.png          | Bin
 examples/package.json                         |   6 +-
 pnpm-lock.yaml                                | 123 +-----------------
 15 files changed, 16 insertions(+), 167 deletions(-)
 delete mode 100644 apps/mongodb/CHANGELOG.md
 delete mode 100644 apps/mongodb/package.json
 rename {apps/mongodb => examples/data}/tinytweets.json (100%)
 rename {apps => examples}/mongodb/1_import.ts (95%)
 rename {apps => examples}/mongodb/2_load_and_index.ts (100%)
 rename {apps => examples}/mongodb/3_query.ts (100%)
 rename {apps => examples}/mongodb/README.md (93%)
 rename {apps => examples}/mongodb/docs/1_signup.png (100%)
 rename {apps => examples}/mongodb/docs/2_connection_string.png (100%)
 rename {apps => examples}/mongodb/docs/3_vectors_in_db.png (100%)
 rename {apps => examples}/mongodb/docs/4_search_tab.png (100%)
 rename {apps => examples}/mongodb/docs/5_json_editor.png (100%)
 rename {apps => examples}/mongodb/docs/7_index_created.png (100%)

diff --git a/apps/mongodb/CHANGELOG.md b/apps/mongodb/CHANGELOG.md
deleted file mode 100644
index a59c60b4f..000000000
--- a/apps/mongodb/CHANGELOG.md
+++ /dev/null
@@ -1,20 +0,0 @@
-# mongodb-llamaindexts
-
-## 0.0.3
-
-### Patch Changes
-
-- Updated dependencies [3bab231]
-  - llamaindex@0.0.37
-
-## 0.0.2
-
-### Patch Changes
-
-- Updated dependencies
-- Updated dependencies
-- Updated dependencies
-- Updated dependencies
-- Updated dependencies
-- Updated dependencies
-  - llamaindex@0.0.36
diff --git a/apps/mongodb/package.json b/apps/mongodb/package.json
deleted file mode 100644
index de421e1c6..000000000
--- a/apps/mongodb/package.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
-  "version": "0.0.3",
-  "private": true,
-  "name": "mongodb-llamaindexts",
-  "dependencies": {
-    "llamaindex": "workspace:*",
-    "dotenv": "^16.3.1",
-    "mongodb": "^6.2.0"
-  },
-  "devDependencies": {
-    "@types/node": "^18.18.6",
-    "ts-node": "^10.9.1"
-  },
-  "scripts": {
-    "lint": "eslint ."
-  }
-}
\ No newline at end of file
diff --git a/apps/mongodb/tinytweets.json b/examples/data/tinytweets.json
similarity index 100%
rename from apps/mongodb/tinytweets.json
rename to examples/data/tinytweets.json
diff --git a/apps/mongodb/1_import.ts b/examples/mongodb/1_import.ts
similarity index 95%
rename from apps/mongodb/1_import.ts
rename to examples/mongodb/1_import.ts
index 57c9e9bba..73d6a3a87 100644
--- a/apps/mongodb/1_import.ts
+++ b/examples/mongodb/1_import.ts
@@ -6,7 +6,7 @@ import { MongoClient } from "mongodb";
 // Load environment variables from local .env file
 dotenv.config();
 
-const jsonFile = "tinytweets.json";
+const jsonFile = "./data/tinytweets.json";
 const mongoUri = process.env.MONGODB_URI!;
 const databaseName = process.env.MONGODB_DATABASE!;
 const collectionName = process.env.MONGODB_COLLECTION!;
diff --git a/apps/mongodb/2_load_and_index.ts b/examples/mongodb/2_load_and_index.ts
similarity index 100%
rename from apps/mongodb/2_load_and_index.ts
rename to examples/mongodb/2_load_and_index.ts
diff --git a/apps/mongodb/3_query.ts b/examples/mongodb/3_query.ts
similarity index 100%
rename from apps/mongodb/3_query.ts
rename to examples/mongodb/3_query.ts
diff --git a/apps/mongodb/README.md b/examples/mongodb/README.md
similarity index 93%
rename from apps/mongodb/README.md
rename to examples/mongodb/README.md
index 5448191d6..61c8b4886 100644
--- a/apps/mongodb/README.md
+++ b/examples/mongodb/README.md
@@ -2,12 +2,7 @@
 
 ### Prepare Environment
 
-Make sure to run `pnpm install` and set your OpenAI environment variable before running these examples.
-
-```
-pnpm install
-export OPENAI_API_KEY="sk-..."
-```
+Read and follow the instructions in the [README.md](../README.md) file located one directory up to make sure your JS/TS dependencies are set up. The commands listed below are also run from that parent directory.
 
 ### Sign up for MongoDB Atlas
 
@@ -21,7 +16,7 @@ The signup process will walk you through the process of creating your cluster an
 
 ### Set up environment variables
 
-Copy the connection string (make sure you include your password) and put it into a file called `.env` in the root of this repo. It should look like this:
+Copy the connection string (make sure you include your password) and put it into a file called `.env` in the parent folder of this directory. It should look like this:
 
 ```
 MONGODB_URI=mongodb+srv://seldo:xxxxxxxxxxx@llamaindexdemocluster.xfrdhpz.mongodb.net/?retryWrites=true&w=majority
@@ -39,7 +34,7 @@ MONGODB_COLLECTION=tiny_tweets_collection
 You are now ready to import our ready-made data set into Mongo. This is the file `tinytweets.json`, a selection of approximately 1000 tweets from @seldo on Twitter in mid-2019. With your environment set up you can do this by running
 
 ```
-pnpm ts-node 1_import.ts
+npx ts-node mongodb/1_import.ts
 ```
 
 If you don't want to use tweets, you can replace `json_file` with any other array of JSON objects, but you will need to modify some code later to make sure the correct field gets indexed. There is no LlamaIndex-specific code here; you can load your data into Mongo any way you want to.
@@ -64,7 +59,7 @@ MONGODB_VECTOR_INDEX=tiny_tweets_vector_index
 If the data you're indexing is the tweets we gave you, you're ready to go:
 
 ```bash
-pnpm ts-node 2_load_and_index.ts
+npx ts-node mongodb/2_load_and_index.ts
 ```
 
 > Note: this script is running a couple of minutes and currently doesn't show any progress.
@@ -119,7 +114,7 @@ Now you're ready to query your data!
 You can do this by running
 
 ```bash
-pnpm ts-node 3_query.ts
+npx ts-node mongodb/3_query.ts
 ```
 
 This sets up a connection to Atlas just like `2_load_and_index.ts` did, then it creates a [query engine](https://docs.llamaindex.ai/en/stable/understanding/querying/querying.html#getting-started) and runs a query against it.
diff --git a/apps/mongodb/docs/1_signup.png b/examples/mongodb/docs/1_signup.png
similarity index 100%
rename from apps/mongodb/docs/1_signup.png
rename to examples/mongodb/docs/1_signup.png
diff --git a/apps/mongodb/docs/2_connection_string.png b/examples/mongodb/docs/2_connection_string.png
similarity index 100%
rename from apps/mongodb/docs/2_connection_string.png
rename to examples/mongodb/docs/2_connection_string.png
diff --git a/apps/mongodb/docs/3_vectors_in_db.png b/examples/mongodb/docs/3_vectors_in_db.png
similarity index 100%
rename from apps/mongodb/docs/3_vectors_in_db.png
rename to examples/mongodb/docs/3_vectors_in_db.png
diff --git a/apps/mongodb/docs/4_search_tab.png b/examples/mongodb/docs/4_search_tab.png
similarity index 100%
rename from apps/mongodb/docs/4_search_tab.png
rename to examples/mongodb/docs/4_search_tab.png
diff --git a/apps/mongodb/docs/5_json_editor.png b/examples/mongodb/docs/5_json_editor.png
similarity index 100%
rename from apps/mongodb/docs/5_json_editor.png
rename to examples/mongodb/docs/5_json_editor.png
diff --git a/apps/mongodb/docs/7_index_created.png b/examples/mongodb/docs/7_index_created.png
similarity index 100%
rename from apps/mongodb/docs/7_index_created.png
rename to examples/mongodb/docs/7_index_created.png
diff --git a/examples/package.json b/examples/package.json
index 23e651d50..8375b6005 100644
--- a/examples/package.json
+++ b/examples/package.json
@@ -6,7 +6,9 @@
     "@notionhq/client": "^2.2.13",
     "@pinecone-database/pinecone": "^1.1.2",
     "commander": "^11.1.0",
-    "llamaindex": "latest"
+    "llamaindex": "latest",
+    "dotenv": "^16.3.1",
+    "mongodb": "^6.2.0"
   },
   "devDependencies": {
     "@types/node": "^18.18.6",
@@ -15,4 +17,4 @@
   "scripts": {
     "lint": "eslint ."
   }
-}
+}
\ No newline at end of file
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 07f9d7caf..6cb31f017 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -104,25 +104,6 @@ importers:
         specifier: ^4.9.5
         version: 4.9.5
 
-  apps/mongodb:
-    dependencies:
-      dotenv:
-        specifier: ^16.3.1
-        version: 16.3.1
-      llamaindex:
-        specifier: workspace:*
-        version: link:../../packages/core
-      mongodb:
-        specifier: ^6.2.0
-        version: 6.2.0
-    devDependencies:
-      '@types/node':
-        specifier: ^18.18.6
-        version: 18.18.8
-      ts-node:
-        specifier: ^10.9.1
-        version: 10.9.1(@types/node@18.18.8)(typescript@5.3.2)
-
   examples:
     dependencies:
       '@notionhq/client':
@@ -134,9 +115,15 @@ importers:
       commander:
         specifier: ^11.1.0
         version: 11.1.0
+      dotenv:
+        specifier: ^16.3.1
+        version: 16.3.1
       llamaindex:
         specifier: latest
         version: link:../packages/core
+      mongodb:
+        specifier: ^6.2.0
+        version: 6.3.0
     devDependencies:
       '@types/node':
         specifier: ^18.18.6
@@ -4461,12 +4448,6 @@ packages:
     dependencies:
       undici-types: 5.26.5
 
-  /@types/node@18.18.8:
-    resolution: {integrity: sha512-OLGBaaK5V3VRBS1bAkMVP2/W9B+H8meUfl866OrMNQqt7wDgdpWPp5o6gmIc9pB+lIQHSq4ZL8ypeH1vPxcPaQ==}
-    dependencies:
-      undici-types: 5.26.5
-    dev: true
-
   /@types/node@20.9.0:
     resolution: {integrity: sha512-nekiGu2NDb1BcVofVcEKMIwzlx4NjHlcjhoxxKBNLtz15Y1z7MYf549DFvkHSId02Ax6kGwWntIBPC3l/JZcmw==}
     dependencies:
@@ -4641,13 +4622,6 @@ packages:
       '@types/webidl-conversions': 7.0.2
     dev: false
 
-  /@types/whatwg-url@8.2.2:
-    resolution: {integrity: sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==}
-    dependencies:
-      '@types/node': 18.18.12
-      '@types/webidl-conversions': 7.0.2
-    dev: false
-
   /@types/ws@8.5.6:
     resolution: {integrity: sha512-8B5EO9jLVCy+B58PLHvLDuOD8DRVMgQzq8d55SjLCOn9kqGyqOvy27exVaTio1q1nX5zLu8/6N0n2ThSxOM6tg==}
     dependencies:
@@ -10940,13 +10914,6 @@ packages:
     hasBin: true
     dev: true
 
-  /mongodb-connection-string-url@2.6.0:
-    resolution: {integrity: sha512-WvTZlI9ab0QYtTYnuMLgobULWhokRjtC7db9LtcVfJ+Hsnyr5eo6ZtNAt3Ly24XZScGMelOcGtm7lSn0332tPQ==}
-    dependencies:
-      '@types/whatwg-url': 8.2.2
-      whatwg-url: 11.0.0
-    dev: false
-
   /mongodb-connection-string-url@3.0.0:
     resolution: {integrity: sha512-t1Vf+m1I5hC2M5RJx/7AtxgABy1cZmIPQRMXw+gEIPn/cZNF3Oiy+l0UIypUwVB5trcWHq3crg2g3uAR9aAwsQ==}
     dependencies:
@@ -10954,38 +10921,6 @@ packages:
       whatwg-url: 13.0.0
     dev: false
 
-  /mongodb@6.2.0:
-    resolution: {integrity: sha512-d7OSuGjGWDZ5usZPqfvb36laQ9CPhnWkAGHT61x5P95p/8nMVeH8asloMwW6GcYFeB0Vj4CB/1wOTDG2RA9BFA==}
-    engines: {node: '>=16.20.1'}
-    peerDependencies:
-      '@aws-sdk/credential-providers': ^3.188.0
-      '@mongodb-js/zstd': ^1.1.0
-      gcp-metadata: ^5.2.0
-      kerberos: ^2.0.1
-      mongodb-client-encryption: '>=6.0.0 <7'
-      snappy: ^7.2.2
-      socks: ^2.7.1
-    peerDependenciesMeta:
-      '@aws-sdk/credential-providers':
-        optional: true
-      '@mongodb-js/zstd':
-        optional: true
-      gcp-metadata:
-        optional: true
-      kerberos:
-        optional: true
-      mongodb-client-encryption:
-        optional: true
-      snappy:
-        optional: true
-      socks:
-        optional: true
-    dependencies:
-      '@mongodb-js/saslprep': 1.1.1
-      bson: 6.2.0
-      mongodb-connection-string-url: 2.6.0
-    dev: false
-
   /mongodb@6.3.0:
     resolution: {integrity: sha512-tt0KuGjGtLUhLoU263+xvQmPHEGTw5LbcNC73EoFRYgSHwZt5tsoJC110hDyO1kjQzpgNrpdcSza9PknWN4LrA==}
     engines: {node: '>=16.20.1'}
@@ -14615,13 +14550,6 @@ packages:
       punycode: 2.3.1
     dev: true
 
-  /tr46@3.0.0:
-    resolution: {integrity: sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==}
-    engines: {node: '>=12'}
-    dependencies:
-      punycode: 2.3.1
-    dev: false
-
   /tr46@4.1.1:
     resolution: {integrity: sha512-2lv/66T7e5yNyhAAC4NaKe5nVavzuGJQVVtRYLyQ2OI8tsJ61PMLlelehb0wi2Hx6+hT/OJUWZcw8MjlSRnxvw==}
     engines: {node: '>=14'}
@@ -14721,37 +14649,6 @@ packages:
       yn: 3.1.1
     dev: true
 
-  /ts-node@10.9.1(@types/node@18.18.8)(typescript@5.3.2):
-    resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
-    hasBin: true
-    peerDependencies:
-      '@swc/core': '>=1.2.50'
-      '@swc/wasm': '>=1.2.50'
-      '@types/node': '*'
-      typescript: '>=2.7'
-    peerDependenciesMeta:
-      '@swc/core':
-        optional: true
-      '@swc/wasm':
-        optional: true
-    dependencies:
-      '@cspotcode/source-map-support': 0.8.1
-      '@tsconfig/node10': 1.0.9
-      '@tsconfig/node12': 1.0.11
-      '@tsconfig/node14': 1.0.3
-      '@tsconfig/node16': 1.0.4
-      '@types/node': 18.18.8
-      acorn: 8.11.2
-      acorn-walk: 8.3.0
-      arg: 4.1.3
-      create-require: 1.1.1
-      diff: 4.0.2
-      make-error: 1.3.6
-      typescript: 5.3.2
-      v8-compile-cache-lib: 3.0.1
-      yn: 3.1.1
-    dev: true
-
   /tsconfig-paths@3.14.2:
     resolution: {integrity: sha512-o/9iXgCYc5L/JxCHPe3Hvh8Q/2xm5Z+p18PESBU6Ff33695QnCHBEjcytY2q19ua7Mbl/DavtBOLq+oG0RCL+g==}
     dependencies:
@@ -15710,14 +15607,6 @@ packages:
     engines: {node: '>=0.8.0'}
     dev: false
 
-  /whatwg-url@11.0.0:
-    resolution: {integrity: sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==}
-    engines: {node: '>=12'}
-    dependencies:
-      tr46: 3.0.0
-      webidl-conversions: 7.0.0
-    dev: false
-
   /whatwg-url@13.0.0:
     resolution: {integrity: sha512-9WWbymnqj57+XEuqADHrCJ2eSXzn8WXIW/YSGaZtb2WKAInQ6CHfaUUcTyyver0p8BDg5StLQq8h1vtZuwmOig==}
     engines: {node: '>=16'}
-- 
GitLab