3 / 3
May 2024

Hello guys, i had created a Mongo Atlas to run locally using a compose like this:

name: api networks: api: name: api services: api-mongo-atlas: image: mongodb/atlas hostname: mongo-atlas container_name: api-mongo-atlas ports: [ "${MONGO_PORT}:${MONGO_PORT}" ] networks: [ "api" ] privileged: true command: "bash -c '\ atlas deployments setup \ --type local \ --bindIpAll \ --port ${MONGO_PORT} \ --username ${MONGO_USERNAME} \ --password ${MONGO_PASSWORD} \ --force && tail -f /dev/null'" healthcheck: test: [ "CMD", "mongosh", "--host", "localhost", "--port", "${MONGO_PORT}", "-u", "${MONGO_USERNAME}", "-p", "${MONGO_PASSWORD}", "--eval", "db.stats()" ] interval: 10s timeout: 5s retries: 20

When I enter in container and try create an collection with Search Index this error appear:

$ docker exec -it opus-mongo-atlas bash [root@mongo-atlas /]# mongosh mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@localhost:${MONGO_PORT}/?directConnection=true Current Mongosh Log ID: 663287073bde1bfd612202d7 Connecting to: mongodb://<credentials>@localhost:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.5 Using MongoDB: 7.0.9 Using Mongosh: 2.2.5 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ AtlasLocalDev rs-localdev [direct: primary] test> use db switched to db db AtlasLocalDev rs-localdev [direct: primary] db> db.createCollection("keys"); { ok: 1 } AtlasLocalDev rs-localdev [direct: primary] db> AtlasLocalDev rs-localdev [direct: primary] db> db.getCollection('keys').createSearchIndex({ ... name: "keys_fullTextSearch", ... definition: { ... organizationName: {type: "string"}, ... permissions: {type: "string"} ... } ... }); MongoServerError[UnknownError]: "userCommand.indexes[0].mappings" is required AtlasLocalDev rs-localdev [direct: primary] db>

Why when I use MongoDB Compass with the same connection it’s works but when I tried using a mongosh script they don’t? I need create a minimal environment structure using scripts to manage migrations between development environment and production. Someone can help me plz? :face_holding_back_tears::face_holding_back_tears::face_holding_back_tears: