MongoDB 和猫鼬的区别 [英] Difference between MongoDB and Mongoose

查看:33
本文介绍了MongoDB 和猫鼬的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 mongodb 数据库,但我注意到有两个不同的数据库,它们都有自己的网站和安装方法:mongodb 和 mongoose.所以我想出了这个问题:我用哪个?".

I wanted to use the mongodb database, but I noticed that there are two different databases with either their own website and installation methods: mongodb and mongoose. So I came up asking myself this question: "Which one do I use?".

所以为了回答这个问题,我问社区你是否能解释一下这两者之间的区别是什么?如果可能的话,利弊?因为他们真的很像我.

So in order to answer this question I ask the community if you could explain what are the differences between these two? And if possible pros and cons? Because they really look very similar to me.

推荐答案

我假设您已经知道 MongoDB 是一个 NoSQL 数据库系统,它以 BSON 文档的形式存储数据.但是,您的问题是关于 Node.js 的包.

I assume you already know that MongoDB is a NoSQL database system which stores data in the form of BSON documents. Your question, however is about the packages for Node.js.

就 Node.js 而言,mongodb原生驱动strong> 用于与 mongodb 实例交互,mongoose 是一个对象建模工具强> 用于 MongoDB.

In terms of Node.js, mongodb is the native driver for interacting with a mongodb instance and mongoose is an Object modeling tool for MongoDB.

mongoose 构建在 mongodb 驱动程序之上,为程序员提供了一种对其数据建模的方法.

mongoose is built on top of the mongodb driver to provide programmers with a way to model their data.

我不想评论哪个更好,因为这会使这个答案自以为是.不过,我将列出使用这两种方法的一些优点和缺点.

I do not want to comment on which is better, as this would make this answer opinionated. However I will list some advantages and disadvantages of using both approaches.

使用 mongoose,用户可以为特定集合中的文档定义架构.它为MongoDB中数据的创建和管理提供了很多便利.不利的一面是,学习 mongoose 可能需要一些时间,并且在处理非常复杂的模式方面存在一些局限性.

Using mongoose, a user can define the schema for the documents in a particular collection. It provides a lot of convenience in the creation and management of data in MongoDB. On the downside, learning mongoose can take some time, and has some limitations in handling schemas that are quite complex.

但是,如果您的集合架构不可预测,或者您想要在 Node.js 中获得类似 Mongo-shell 的体验,那么请继续使用 mongodb 驱动程序.捡起来最简单.这里的缺点是您将不得不编写大量代码来验证数据,并且出错的风险更高.

However, if your collection schema is unpredictable, or you want a Mongo-shell like experience inside Node.js, then go ahead and use the mongodb driver. It is the simplest to pick up. The downside here is that you will have to write larger amounts of code for validating the data, and the risk of errors is higher.

这篇关于MongoDB 和猫鼬的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆