ModeShape only interacts with the Mongo Java Driver (the db.collectionExists is a driver method). Looking at the latest driver code (mongo-java-driver/DB.java at master · mongodb/mongo-java-driver · GitHub ) the implementation for this particular method is pretty much the same as in the version that ModeShape uses, meaning it hasn't been reported (yet) as a performance issue.
If this were a performance issue, I would expect the driver folks to fix it - perhaps you can take this issue up with them.
Regarding your proposed alternative: mongoDatabase.listCollections().filter(new Document("name", collectionName)).isEmpty() - I don't see these APIs anywhere in the driver so I'm not sure how the ModeShape code could be changed to use this approach (the driver version used by ModeShape is 2.14.0)
Thanks for your answer.
Since, Mongo Java Driver 3.0 the method getDB from MongoClient is deprecated. New MongoData instance returned by getDatabase method should be used. So, new code mongoDatabase.listCollections().filter(new Document("name", collectionName)).first()!=null can be used.
I'm using Mongo Java Driver 3.3.0
Ok, so this would mean we'd have to change the driver version we're using and migrate from 2.x to 3.x. It's something which we can investigate for 5.3, so feel free to log an enhancement JIRA for this. Thanks.