Everyone uses mongoose!
I do not like mongoose, all the abstractions that it implements have not been very useful when making complex transactions that require more of one query to work. Also, i end up learning "mongoose" instead of mongodb.
However, I recognize the importance of the scheme, since it "facilitates" the reading of the code for other programmers of the team.
Normally (talking about an api), the first thing I do with the incoming data is to check and validate them so that the controllers work only with "clean" data and do not have to work in vain if any incoming data is incorrect.
Due to the previous thing, to implement schemes in the model becomes unnecessary, since the data are validated. I like this, but there is still a problem, the programmers must analyze the validators, to understand what type of data they are handling.
The easiest solution would be to create the scheme, even though the data is already validated, but this would lead to repeating a lot of code throughout the application.
Do you think that the schemes are overvalued?
Am I missing something?
Have you experienced something similar?
How have they solved it?
Any useful advice for a newbie?
I know it might seem silly, but lately I'm "a little bit" more attentive to architecture, and I see that working without schemes and models goes against to the MVC.
Latest comments (40)
I am using native mongodb. Yeah, I'm doing a crawler. So I need to record data directly in the database without needing schemas. The problem is that the MongoDB drive documentation for Node is out of date and for more elaborate things it is quite complicated to find documentation. Everyone uses mongoose. And think, in the case of service communication. OK! Use. But, in the case of reading a url, extraction, insertion in the database. Then if you fall into an error you end up not finding the solution easily. For outdated documentation and growth of mongoose. If anyone knows of any solution to work with great load with NodeJS and native MongoDB. I'm grateful.
I'm glad to see some other people also questioning, and not just blindly accepting something which everything else was doing..
I suppose this is definitely one of those topics which very much depends on you personality type and view of the world: I tend to like un-opinionated frameworks - I like the freedom to find solutions on my own terms.
Schemas/ORMs (like via mongoose) make me feel like i'm being forced into a box.
At the beginning I want to save time, so I learned mongoose. When I need to use aggregation/lookup or similar, I don't know how to it in mongoose or feel to be restricted.
Now I back to mongodb native. I get all, especially, freedom.
Why I should use mongoose when I am looking desperately to move to MongoDB in order to get rid of all kind of nonsense schemas.... only usefullness I find is that it can provide an abstraction layer to work with OOP applications in format of model...
BUT basically I will choose native Mongo to avoid break for schema... please coreect if there is any other usefulness Mongo can provide....
I realize this is an old thread, but thought I'd reply here for others who come along like I did. :-)
Although I'm new to MongoDB and GraphQL, I think that is the best reason for why one would want to have (or need) a Schema with a something like MongoDB.
I'm still working through whether to use mongodb-native or mongoose ... but thought I'd share that as I've been learning GraphQL, making sure that I have consistency between my schemas and resolvers has been helpful.
Isn't Mongoose like spoon feeding? I had a really bad experience with mongoose for a large data set.
If you're going large you should go with the Father.
@Jacob you spoke my words. Thanks for this post
Panacea - There is none in coding.
Today you might not want or need mongoose, other times you might.
It’s a tool, just because you decided it isn’t the tool for your current job doesn’t mean it doesn’t belong in your toolbox.
You could create a joi schema as MW to validate your data and keep a reference of what kind of data you are saving.
In fact, I use joi, it is very good and allows for deeper validations, even sanitation and escaping.
the first db I learned was mongo and now I’m looking at sql. I wonder what they’re good for....
This is coming from someone who wants to make tiny web apps that take open data and with hundreds of users in mind only
If you know well the concurrence of what you are going to build, it is a great advantage.
In my opinion, if your data manages "many to many" relationships you should use relational databases, even for "one to many". You can make complex relationships in mongodb, but you should make several calls to the database to populate the references, which translates into more code lines and more checks. If that does not concern you, then go for mongodb.
As an extra note, with mongoose you do not have to worry about references, since he handles them for you. It's one of his advantages!
I do not like mongoose, but I'm aware that it's very useful.
Mongodb, or any other noSQL, stands out in applications that handle very specific relationships.
Also, it is very useful for applications in constant change and evolution, it works great in methodologies that use the "minimum viable product", since it allows you to modify the flow of data easily, thanks to its flexible scheme.
Another thing that stands out from mongo is its native ability to scale horizontally.
All this is my opinion and experience. I currently use mongo because it works well with nodejs and it was the first thing I learned. However, I want to learn postgreSQL in the future, since a query language has its own benefits.
thanks for sharing your experience. I’ve used mongoose once (forgot about it) and mongo native driver since then. Ive been doing Postgres queries at work and I find that it’s much more semantic than mongo .find() etc but I can see how relationships between tables are very structured to begin with. I’ve yet to see how creating and updating a sql db differs; will have to report back on that one!
I've used Mongo in my node apps for at least 7 years, I've used Mongoose once in that time, and hated it (was chosen before I got onto the project) Otherwise I've either used mongojs or mongodb, much nicer experience. If you are using a schema-less db, why on earth do you want to bring in a schema? Maybe validation? But really, your validation should probably be somewhere before hitting the db/model, at either the api entry point or before it ever leaves the browser. So validation should be sharable between the client and server, not at the db level.
That's!
That's what I think about validation, and that's the main reason why I migrated to the native controller.
Great discussion!
I am still using MongoDB naive driver for my applications, my seriously considering moving to mongoose.
The main reason is that security (JWT e.g.), modeling and verification (ObjectID e.g.) would be much easier and cleaner with mongoose.
Using mongoose bulit-in library, would allow you to reduce code from your project and let you focus on your core application.
Very true, sometimes we forget that productivity matters. With mongoose we are definitely more productive.