I am trying to compare native Java mongoDB connect...
# adobe
e
I am trying to compare native Java mongoDB connectors to the embedded ACF21 functionality. I have been trying to get the native stuff to work, but I keep getting authentication connection issues.
I am using a simple container like this:
Copy code
version: '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:
Copy code
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:
I have added the connection in the administrator and I use this code:
Copy code
collection = getMongoService("cfmongo").db("admin").getCollection("visits");
results = collection.find();
writedump(results);
The connection string in Compass looks like this:
Copy code
<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:
Copy code
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"}
I have tried every single thing I can think of to get the connector to successfully query, but still the same issue. I have made sure the
admin
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.
p
Yea that is odd, what about doing
collection.find().toArray();
even if that doesnt work, something is fishy, def look at logs
e
same issue. Even Adobe's recommendation does not work:
Copy code
results.foreach((s) => { 
	writedump(s);
});
p
Yea appears to be a bug