Good morning,
I need to create a search index in my local deployment of atlas, using a docker compose. I have my client in node with the following code:
import { MongoClient } from "mongodb";
const client = new MongoClient(
"mongodb://user:pass@mongodb:27017/?directConnection=true"
);
async function run() {
try {
await client.connect();
const db = client.db("testDb");
const collection = db.collection("testCollection");
console.log("Connected successfully to server");
const index = {
name: `vi-1`,
type: "vectorSearch",
definition: {
"fields": [
{
"type": "vector",
"numDimensions": 768,
"path": "textEmbedding",
"similarity": "cosine"
},
{
"type": "filter",
"path": "company"
},
{
"type": "filter",
"path": "phone"
},
]
}
}
await collection.createSearchIndex(index);
} finally {
await client.close();
}
}
run();
And running the MongoDB server with the compose file written in the docs, this is the whole compose file with both services:
version: '3.8'
services:
mongodb:
image: mongodb/mongodb-atlas-local
environment:
- MONGODB_INITDB_ROOT_USERNAME=user
- MONGODB_INITDB_ROOT_PASSWORD=pass
ports:
- 27017:27017
volumes:
- ./data:/data/db
user: root:root
client:
build:
context: ./db
depends_on:
- mongodb
volumes:
data:
This is the clitent’s Dockerfile:
FROM node:20.16.0
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD [ "node", "db.js" ]
Note that this issue does not happen if I run the client code manually in my computer, using a localhost URL.