From e7fe4e33fc1ce34faf21c1fa56f6a55c7c7edc68 Mon Sep 17 00:00:00 2001 From: matsue2309 Date: Thu, 28 May 2026 06:59:13 +0000 Subject: [PATCH 1/2] =?UTF-8?q?mongoDB=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/Dockerfile | 25 ++++++++++++++++++++++ .devcontainer/devcontainer.json | 35 +++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 36 ++++++++++++++++++++++++++++++++ package-lock.json | 26 +++++++++++------------ package.json | 2 +- 5 files changed, 110 insertions(+), 14 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..398c7004 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,25 @@ +FROM mcr.microsoft.com/devcontainers/javascript-node:4-24-bookworm + +# Install MongoDB command line tools - though mongo-database-tools not available on arm64 +ARG MONGO_TOOLS_VERSION=6.0 +RUN . /etc/os-release \ + && curl -sSL "https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc" | gpg --dearmor > /usr/share/keyrings/mongodb-archive-keyring.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/debian ${VERSION_CODENAME}/mongodb-org/${MONGO_TOOLS_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list \ + && apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get install -y mongodb-mongosh \ + && if [ "$(dpkg --print-architecture)" = "amd64" ]; then apt-get install -y mongodb-database-tools; fi \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment if you want to install an additional version of node using nvm +# ARG EXTRA_NODE_VERSION=10 +# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" + +# [Optional] Uncomment if you want to install more global node modules +# RUN su node -c "npm install -g " + + + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..c14872d7 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,35 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node-mongo +{ + "name": "Node.js & Mongo DB", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "mongodb.mongodb-vscode", + "streetsidesoftware.code-spell-checker" + ] + } + }, + "features": { + "ghcr.io/devcontainers-extra/features/jshint:2": {} + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [3000, 27017], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "npm install" + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000..b7ba686b --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,36 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + volumes: + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:db + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + db: + image: mongo:latest + restart: unless-stopped + volumes: + - mongodb-data:/data/db + + # Uncomment to change startup options + # environment: + # MONGO_INITDB_ROOT_USERNAME: root + # MONGO_INITDB_ROOT_PASSWORD: example + # MONGO_INITDB_DATABASE: your-database-here + + # Add "forwardPorts": ["27017"] to **devcontainer.json** to forward MongoDB locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + +volumes: + mongodb-data: \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8b612d5c..d588169b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "helmet": "^8.1.0", "http-errors": "^2.0.0", "luxon": "^3.6.1", - "mongoose": "^9.2.1", + "mongoose": "^9.6.3", "morgan": "^1.10.0", "pug": "^3.0.3" }, @@ -1300,9 +1300,9 @@ } }, "node_modules/kareem": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/kareem/-/kareem-3.2.0.tgz", - "integrity": "sha512-VS8MWZz/cT+SqBCpVfNN4zoVz5VskR3N4+sTmUXme55e9avQHntpwpNq0yjnosISXqwJ3AQVjlbI4Dyzv//JtA==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-3.3.0.tgz", + "integrity": "sha512-kpSuLD3/7RenBnjnJdOHXCKC8dTd1JzeOiJhN0necWWci6cC+qX+VuwPnMVgb+a4+KNJSfgqahpnfWaeDXCimw==", "license": "Apache-2.0", "engines": { "node": ">=18.0.0" @@ -1553,13 +1553,13 @@ } }, "node_modules/mongoose": { - "version": "9.2.1", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-9.2.1.tgz", - "integrity": "sha512-fmNLwgct5km7iL1MqvTMncarR1E1TIw2lmc9A4UoDVdS7AQe95K+DnRK0qATkSUdwUC9V/5wlDcqnkQQjbSRkA==", + "version": "9.6.3", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-9.6.3.tgz", + "integrity": "sha512-vI6dTTlQnfMCyyQ5TrvhG0bCRs4dq5e1uFNPtOOWsOhn0fSg8AoIHjfyyCYr8aybyvPs845dRHGxsC3w/fHcBA==", "license": "MIT", "dependencies": { - "kareem": "3.2.0", - "mongodb": "~7.0", + "kareem": "3.3.0", + "mongodb": "~7.2", "mpath": "0.9.0", "mquery": "6.0.0", "ms": "2.1.3", @@ -1592,13 +1592,13 @@ } }, "node_modules/mongoose/node_modules/mongodb": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.0.0.tgz", - "integrity": "sha512-vG/A5cQrvGGvZm2mTnCSz1LUcbOPl83hfB6bxULKQ8oFZauyox/2xbZOoGNl+64m8VBrETkdGCDBdOsCr3F3jg==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.2.0.tgz", + "integrity": "sha512-F/2+BMZtLVhY30ioZp0dAmZ+IRZMBqI+nrv6t5+9/1AIwCa8sMRC3jBf81lpxMhnZgqq8CoUD503Z1oZWq1/sw==", "license": "Apache-2.0", "dependencies": { "@mongodb-js/saslprep": "^1.3.0", - "bson": "^7.0.0", + "bson": "^7.2.0", "mongodb-connection-string-url": "^7.0.0" }, "engines": { diff --git a/package.json b/package.json index 673317c1..a57f11a9 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "helmet": "^8.1.0", "http-errors": "^2.0.0", "luxon": "^3.6.1", - "mongoose": "^9.2.1", + "mongoose": "^9.6.3", "morgan": "^1.10.0", "pug": "^3.0.3" }, From 1760f42f6be8919e35043991fa9ba8d5aaf7a846 Mon Sep 17 00:00:00 2001 From: matsue2309 Date: Thu, 28 May 2026 07:20:07 +0000 Subject: [PATCH 2/2] =?UTF-8?q?MONGODB=E8=A8=AD=E5=AE=9A=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/www | 2 +- package-lock.json | 7 +++++++ package.json | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/www b/bin/www index 8a9a4249..f7dd43d2 100644 --- a/bin/www +++ b/bin/www @@ -20,7 +20,7 @@ app.set("port", port); */ const mongoose = require("mongoose"); const dev_db_url = - "mongodb+srv://cooluser:coolpassword@cluster0.cojoign.mongodb.net/local_library?retryWrites=true&w=majority&appName=Cluster0"; + "mongodb://localhost:27017/local_library"; const mongoDB = process.env.MONGODB_URI || dev_db_url; try { diff --git a/package-lock.json b/package-lock.json index d588169b..9e6f32b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "express-locallibrary-tutorial", "version": "0.0.1", "dependencies": { + "async": "^3.2.6", "compression": "^1.8.0", "cookie-parser": "^1.4.7", "debug": "^4.4.1", @@ -194,6 +195,12 @@ "integrity": "sha512-5oJg84os6NMQNl27T9LnZkvvqzvAnHu03ShCnoj6bsJwS7L8AO4lf+C/XjK/nvzEqQB744moC6V128RucQd1jA==", "license": "MIT" }, + "node_modules/async": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", + "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", + "license": "MIT" + }, "node_modules/async-mutex": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.5.0.tgz", diff --git a/package.json b/package.json index a57f11a9..0d02ee01 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "test": "node --test" }, "dependencies": { + "async": "^3.2.6", "compression": "^1.8.0", "cookie-parser": "^1.4.7", "debug": "^4.4.1",