Logo

dev-resources.site

for different kinds of informations.

Bootcamping 01: An Unexpected Behavior of Mongoose

Published at
10/10/2024
Categories
findone
mongoose
mongodb
bootcamp
Author
aleflewitt
Categories
4 categories in total
findone
open
mongoose
open
mongodb
open
bootcamp
open
Author
10 person written this
aleflewitt
open
Bootcamping 01: An Unexpected Behavior of Mongoose

When you’re a student in a bootcamp, you’re introduced to so many new
technologies all at once, and sometimes it can be overwhelming. One approach that I’ve found helpful is to try and identify what each technology is adding. Ask yourself - what problem is this technology coming to solve? Why do we need it in the first place?

The tendency to not ask these questions, may stem from a feeling of professionalism that comes with using a new package or technology. It can seem “cool” or “tech-y” to add new jargon to your toolbox, that this can cloud the true professionalism, which is to ask “why do I actually need this package in my project?” Lugging around an unnecessary package can cause more harm than help when deploying and it’s important to attempt to understand the helpfulness of a given package you plan on using in your project.

In coding bootcamps, when teaching usage of the MongoDB database, it’s common to almost immediately use it with the additional package “Mongoose”. Why? What does this third-party library add to the regular MongoDB?

Besides the basic advantages of rigid schemas and models (see this fantastic article by Jesse Hall, Getting Started with MongoDB & Mongoose), there are some hidden advantages, one of which I recently discovered.

A student of mine was using the findOne method, passing it a query value which was “undefined”, (for example, findOne({username}) where username is undefined and in response he was receiving an actual MongoDB document. I was surprised? The MongoDB documentation clearly states that such a case should in-fact respond with “null”!

The answer I discovered lies in one way that Mongoose is “smarter” than MongoDB. Mongoose, in its attempt to only return documents and avoid returning null, won’t ‘agree’ as it were, to send a request of findOne with an undefined query, and so, behind the scenes, when Mongoose’s findOne method is passed an undefined query value, it doesn’t send that query to MongoDB - it first translates the undefined into an empty object, and in-turn, generates a response of an actual document instead of null.

Food for thought: Is this an advantage or a disadvantage? What are your thoughts?

Happy learning! Stay curious, and please share your thoughts!

bootcamp Article's
30 articles in total
Favicon
Hey Guys I just heard about this interesting bootcamp!
Favicon
surviving coding bootcamp: project planning
Favicon
How I stayed motivated to ACE my Full-Stack Coding Bootcamp!
Favicon
Bootcamping 01: An Unexpected Behavior of Mongoose
Favicon
Bootcamp for Brazilian Developers!
Favicon
Check out mock interviews, boot camps, shout out etc. on https://bediactiverightnow.com/ .
Favicon
surviving coding bootcamp: lessons learned
Favicon
What has Changed? - CodingDojo
Favicon
Do I Take Anything Back From the Past Posts? - YES!!!
Favicon
Considerations on how to Start Career in Data Science: Advice aimed at Turning Beginners into Pros📈
Favicon
Finished prework study guide
Favicon
AppWorks School - Week 2
Favicon
AppWorks School - Week 1
Favicon
Top 5 Best Backend Bootcamps and Why (2024)
Favicon
AppWorks School - Week 0
Favicon
capstone debugging: learnings
Favicon
Mustard and serving hatches (or 'How I explain what I'm learning to my parents…')
Favicon
Starting a bootcamp
Favicon
Bootcamp De ServiceNow Gratuito Com Chance De Contratação
Favicon
OracleBootCamp - 4 May 2024
Favicon
ÂżMe conviene un Bootcamp TecnolĂłgico?
Favicon
University over Bootcamp: Why I Chose Traditional Education for My Tech Journey
Favicon
Embracing Change: My Journey into Software Engineering with TripleTen
Favicon
SQL Bootcamp: Beginner to Advanced Course
Favicon
Data Science Bootcamp - Full Course for Beginners
Favicon
HTML and GIT
Favicon
OracleBootCamp - 20 Jan 2024
Favicon
Higher Order Functions
Favicon
Northcoders Week 2: Shut up and take my money! 💷
Favicon
Where does the code live?

Featured ones: