Ben Nadel looks at how to extract MongoDB database and collection names from an ENV-based connection string such that the document database can be consumed more opaquely in Lucee CFML 188.8.131.52.
At InVision, I'm working with Boaz Ruck on a little experiment: whereas our ColdFusion application would normally construct a MongoDB connection using a variety of individual values, the Data Services team would like to try providing the entire MongoDB connection configuration as a single environment variable. This way, the Data Service team could tweak the settings without having to touch the application code. This posed an interesting problem because the ColdFusion application is generally tightly coupled to the MongoDB implementation. As such, I needed to figure out how to access a MongoDB Collection using the Java driver without being able to hard-code the database name or the collection name. After some trial-and-error, I figured out how to extract this information from the
ConnectionString object in Lucee CFML 184.108.40.206.
So, normally, when creating and consuming a MongoDB document collection, my ColdFusion code will "hard code" the name of the database and the name of the collection:
mongoClient.getDatabase( "bennadel" ).getCollection( "friends" )
ASIDE: In some cases, the name of the MongoDB database is passed-in as a separate environment variable. It depends on how old the code is; newer code tends to be a bit less hard-coded.
However, the Data Services team would like to try passing all of that information in as a single environment variable:
In the ColdFusion code, however, I still have to make a
.getDatabase(name) call followed by a
.getCollection(name) call before I can start reading and writing MongoDB documents. Which means, my code still has to reference a database name and a collection name. It doesn't appear that I can get this information from the
MongoClient client; but, if I construct a
ConnectionString class from the environment variable, I can then extract the database and collection names from the connection string. This would allow me to consume then in an opaque manner in my Lucee CFML
Ben Nadel takes a moment to reflect on his mental model prepared statements in MySQL. And how he might use the CFQueryParam tag to go about safely creating prepared statements for SQL queries that use the IN clause with a dynamic set of parameters.
Ben Nadel has fun dynamically evaluating ColdFusion String interpolation expressions that are stored in a database using Adobe ColdFusion 2018. This demo uses the evaluate() and de() functions to merge runtime variables into a database-driven value.
Ben Nadel realizes that he's had some pretty large, fundamental misunderstandings of how prepared statements are parsed, cached, and executed when using the MySQL JDBC Driver in his ColdFusion / Lucee / CFML applications. And what implications this has for his use of the CFQueryParam tag.
Ben Nadel looks at using the wkhtmltopdf project in Lucee CFML 220.127.116.11 to generate PDF documents from dynamic, ColdFusion code. He performs his experiment using the Ortus Solutions' CommandBox Docker container.