evagoras
02/10/2025, 11:39 AMevagoras
02/10/2025, 11:43 AMversion: '3.8'
services:
mongodb:
image: mongo:latest
container_name: mongo-sample
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password123
NODE_OPTIONS: "--max-old-space-size=4096"
volumes:
- mongo_data:/data/db
- ./init-scripts:/docker-entrypoint-initdb.d
volumes:
mongo_data:
And an init script of:
db = db.getSiblingDB("admin");
// Insert sample documents into the "visits" collection
db.visits.insertMany([
{ _id: 1, visitor: "Alice", visitDate: new Date(), notes: "First visit" },
{ _id: 2, visitor: "Bob", visitDate: new Date(), notes: "Second visit" },
{ _id: 3, visitor: "Charlie", visitDate: new Date(), notes: "Third visit" }
]);
This seems to work fine and this is what I see in Compass:evagoras
02/10/2025, 11:45 AMcollection = getMongoService("cfmongo").db("admin").getCollection("visits");
results = collection.find();
writedump(results);
The connection string in Compass looks like this:
<mongodb://admin:password123@localhost:27017/?authSource=admin>
Although that successfully dumps an object of object of coldfusion.nosql.mongo.cursor.CFMongoFindIteratorImpl, when I try to act on that result object like results.toArray(), then I get:
ErrorMessage Authentication failed.
Message Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed"}evagoras
02/10/2025, 11:46 AMadmin account has access to that database, tried adding new users, changing the auth database... nothing works.
Suffice to say I can successfully connect, query, and display results by downloading the mongo Java drivers and using pure java to do that.Patrick
02/10/2025, 4:55 PMcollection.find().toArray(); even if that doesnt work, something is fishy, def look at logsevagoras
02/10/2025, 5:36 PMresults.foreach((s) => {
writedump(s);
});Patrick
02/10/2025, 5:48 PM