I have to admit that at least I've started using AI a lot these days and even for my official work. We have a ban on ChatGPT and other AI-based tools in our office, but we have access to GitHub Copilot with a consent form filled out by us. We are allowed to use GitHub Copilot for coding-related help, but we have to fill out the consent form to be very careful with the answers provided by the Copilot. Some of the teams are even using Amazon Q, and I find Copilot itself to be convenient and answers most of my questions.
I have started using more and more AI in my projects to generate code. I know the logic, and I know the basic coding. So I don't have to worry about wrong code provided by AI. I review the code provided by AI before using it in production. For non-production activities, I don't worry too much as long as it gives the output I require. But I do take precautions and review it when required. But most of the time, it is very good.
I recently did a frontend project that was supposed to be a website design. The client had given me the UI designs through figma, and I had to convert it to code and use it in the project. Usually these projects can take upto 3 months or even more than that to just design the UI alone, but I was able to complete it in 3 weeks time. I copy-paste the screenshot of the design to AI, and AI would provide me with the code in my tech stack. Of course, the code may not be 100 percent perfect. I might have to spend an hour or two tweaking the code provided by the AI. But this is far better than doing everything from scratch.
Today, I wanted to do another project where I had a mongo database that had multiple collections with different schemas. I wanted to check if I can get all the collection information with fields and their respective field type. I asked Chat GPT, and it gave me the following code.
// Function to infer field types from sample documents
function inferSchema(collectionName, sampleSize = 100) {
const samples = db.getCollection(collectionName).aggregate([
{ $sample: { size: sampleSize } },
{ $project: { _id: 0 } }
]).toArray();
const schema = {};
samples.forEach(doc => {
for (const key in doc) {
const val = doc[key];
const type =
Array.isArray(val) ? 'Array'
: val === null ? 'Null'
: val instanceof Date ? 'Date'
: typeof val === 'object' ? 'Object'
: typeof val;
schema[key] = schema[key] || new Set();
schema[key].add(type);
}
});
const finalSchema = {};
for (const key in schema) {
finalSchema[key] = Array.from(schema[key]);
}
return finalSchema;
}
// Get all collection names
const collections = db.getCollectionNames();
// Loop through collections and print schema
collections.forEach(coll => {
print(`\n📦 Collection: ${coll}`);
const schema = inferSchema(coll);
printjson(schema);
});
Above is an AI Generated Code
The above code was generated and given, and when I reviewed I noticed that I can do a few tweaks here and there, but it solved my needs. I directly ran this code on my mongo database using NoSQLBooster. The output was perfect and as desired. ChatGPT asked me to provide that output so that it can create a fully working Node.js project with API routes and schema. This is an experimental project to see how I'm able to build my project without any need for writing code myself. Of course, I might have to do some tweaking to the output provided by Chat GPT. But this is awesome, and this is yet another example of how the future of development is looking like. No wonder that freshers are finding it hard to get into IT jobs.
If you like what I'm doing on Hive, you can vote me as a witness with the links below.
![]() |
![]() |
![]() |
Posted Using INLEO