This is the first line used to describe moongoosejs.com
mongodb object modeling for node.js
I am currently using Mongoose but because I have never used bare mongoDB perhaps I don't understand the line.
I know what all the words means separately but not together. Does object
refer to the object literals I use to define my schemas?
Or something more specific?
CodePudding user response:
You have to think about the context of the document you are reading, in this case databases.
So objects will refer to database objects and from basic CS we know that an object instance is created from a class.
However in the Mongo world you do not create classes you create models, so a model is similar to a class in that you can use it to create an instance using the new keyword.
With these models and object instances you can then manipulate the database as needed.
Hence the terminology
object modeling
CodePudding user response:
mongoDB objects: documents stored in a mongoDB database
modeling: A database can have collections and each collection is a logical set of documents. Models are the basis of collections. Collection is a bag of documents and this bag goes well with a Model because it makes it easier to decide which document should enter into bag and which pattern all documents should share(Schema Validation).
for node.js: Obviously, it means we can't use mongoose on PHP, Python etc.
So, what if you don't model mongoDB objects with mongoose? Well I haven't used pure MongoDB but I can say that without mongoose:
- Your database will be loosely structured
- It will contain more lines of code for basic database operations.
For more info: Why do we need, what advantages to use mongoose
CodePudding user response:
It's an object representation of what's stored in your database. Anyway I have used mongoose a lot, and I tend to stay away from it because nodejs is not an object oriented language and handling object feels messy.
If you really want to use mongoose it would be better to use typescript (with typegoose) to make the use of objects easier.
Finally, I don't use mongoose or typegoose and just write raw query because mongodb is not a relational DB (and that's what an ORM is made for), it's true that you can work with relationship but it's not the way it's meant to be used.