gpt4 book ai didi

node.js - 为什么 Node.js 需要 Mongoose 或 Mongojs?

转载 作者:IT老高 更新时间:2023-10-28 22:02:48 27 4
gpt4 key购买 nike

主要问题

目前我很困惑,主要问题是:Mongoose/Mongojs有什么用?如果我在没有Mongoose/Mongojs的情况下运行Node.js会有什么不同?

我找不到任何关于 Mongoose 或 Mongojs 如何与 Node.js 结合的大图的好的解释。

Mongoose 的口号:“node.js 的优雅 mongodb 对象建模”没有帮助。

小问题

顺便说一句,我认为 Mongoose 和 Mongojs 正在为 Node.js 做相同类型的事情(即可互换),但是 this page似乎在描述 Mongojs 与 Mongoose 完全不同:“尽可能模拟 mongodb API 的简单驱动程序。”所以我把 Mongoose 和 Mongojs 放在一起可能是错误的。如果是这样,也请澄清。


也许我不应该使用 Mongojs,因为 stackoverflow 甚至没有标签。如果是这样,请忽略我上面所说的关于 Mongojs 的所有内容。


关于使用 Mongoose 和 Mongojs 提供 Node.js 的大图的主题,this page 上还有什么?我应该知道吗?

谢谢。

最佳答案

路易斯·埃利松多说:

Quick post. I’ve been using Node.js a lot, to be honest, I love it, along with Node, I’ve been using MongoDB which, as you may know if you read my last post, doesn’t support joins.

My first choice on a project was to use mongojs because it was plain simple. It uses the same structure you use on MongoDB directly with a very few exceptions, the main one is the ability to pass a callback as an argument.

I moved really fast with mongojs, but then I hit a wall. Joins. Is just not possible to do it with MongoJS for the same reason you can’t do it with MongoDB, you have to use some sort of black magic to do them, and this is when Mongoose excells.

To be honest, I tried to avoid Mongoose because I thought it was hard to use, defining a model was just “a waste of time” when with MongoJS you don’t need to. I was wrong.

Bottom line. If your project is really simple, no joins, no complicated features, go with MongoJS, is really easy but limited. If you’re trying to save the world with your crazy idea and you need more powers than Superman, spend some time learning Mongoose and use it, it will take you there.

Trust me, I just spent two days rewriting everything using Mongoose, I wish someone told me before.

http://luiselizondo.net/blogs/luis-elizondo/mongoose-vs-mongojs-nodejs

关于node.js - 为什么 Node.js 需要 Mongoose 或 Mongojs?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16380007/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com