How to create collections in MongoDB Compass with Pre-image support💤
Table of contents
- For Single Collection Creation with Pre-image support👩🏼🤝👨🏻
- Step 1: Switch to the database where you want to create your collections 🔁
- Step 2: Execute the following command to create the collection with pre-image support 🫂
- Alternatively, If you need to create multiple collections with pre-image support then follow the steps🥷:
- Conclusion 🥱
If you need 'fullDocumentBeforeChange
' support in your triggers in change Events then you need to enable this feature while creating the collection.
For Single Collection Creation with Pre-image support👩🏼🤝👨🏻
We'll write commands to this area. Just drag it up.
Step 1: Switch to the database where you want to create your collections 🔁
use <db-name> // use to switch your database
Step 2: Execute the following command to create the collection with pre-image support 🫂
db.createCollection("<collection-name>", {changeStreamPreAndPostImages: {enabled: true}})
As you can see my new collection has been created with pre-image support
Alternatively, If you need to create multiple collections with pre-image support then follow the steps🥷:
Doing these steps again and again for multiple collections is not ideal. There's a better way to do this.
You can use JavaScript forEach
method to create multiple collections in one go.
["coll1", "coll2", "coll3", "coll4", "coll5"].forEach(collection => db.createCollection(collection, {changeStreamPreAndPostImages: {enabled: true}}))
As you can see, multiple collections with pre-image support has been created successfully
Conclusion 🥱
It's very important to enable pre-image support sometimes while using triggers. If you know these methods then our life become a lot easier sometimes.
My Github🙃: AryanKuAg
My LinkedIn🙂: Aryan Agrawal
Thanks for Reading🙏.
Subscribe to my newsletter
Read articles from Aryan Agrawal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Aryan Agrawal
Aryan Agrawal
I have dedicated over 3 years of passionate commitment to programming, consistently building applications and expanding my knowledge of cutting-edge technologies. My commitment is evident through my daily contributions to my GitHub profile. My primary focus and true passion lie in leveraging the power of the MERN stack to develop innovative projects with the latest technologies. Throughout my programming journey, I have acquired expertise in a diverse range of tech skills. This includes proficiency in Python, Flutter, HTML, CSS, JavaScript, ReactJS, Redux, NodeJS, Express.js, MongoDB, MySQL, C++, C, Firebase, Git, GitHub, Next.js, Tailwind CSS, Docker, and Kubernetes. Working with various integrated development environments (IDEs) such as VS Code, Android Studio, Sublime Text Editor, Atom, CodeLite, and Chrome Developer Tools feels natural to me. I am also well-versed in PyCharm, a powerful tool for Python development. In addition to my technical prowess, I bring added value to your company through my proficiency in Adobe Premiere Pro, Figma, Adobe XD, Canva, touch typing (with a typing speed of approximately 80WPM), XARA, Rive 2D, and Heroku. I firmly believe that any opportunity from your side would result in a mutually beneficial collaboration. With an optimistic outlook and a readiness to contribute positive energy to the team, I am confident in making a valuable impact. Feel free to reach out to me through my social media channels. I appreciate the time you took to read my introduction, and I look forward to connecting with you.