node.js 数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2750673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 13:38:11  来源:igfitidea点击:

node.js database

node.jsmongodbcouchdbredis

提问by Justin

I'm looking for a database to pair with a node.js app. I'm assuming a json/nosql db would be preferable to a relational DB [I can do without any json/sql impedance mismatch]. I'm considering:

我正在寻找与 node.js 应用程序配对的数据库。我假设 json/nosql db 比关系数据库更可取 [我可以在没有任何 json/sql 阻抗不匹配的情况下做]。我在考虑:

  • couchdb
  • mongodb
  • redis
  • 沙发数据库
  • MongoDB
  • Redis

Anyone have any views / war stories re compatiability/deployability of the above with node.js? Any clear favorites?

任何人对上述与 node.js 的兼容性/部署性有任何看法/War故事?有明确的收藏夹吗?

回答by christkv

I'm the developer of the mongodb driver for node.js. I'm using mongodb for my own projects and have been very happy with the performance of mongodb.

我是 node.js 的 mongodb 驱动程序的开发人员。我正在将 mongodb 用于我自己的项目,并且对 mongodb 的性能非常满意。

Mongodb driver for node.js

用于 node.js 的 Mongodb 驱动程序

(Shameless plug) Feel free to ask any questions about the driver at

(无耻的插头)请随时向驱动程序询问任何问题

Google group for the mongodb driver

mongodb 驱动程序的 Google 群组

or here at Stackoverflow

或在 Stackoverflow 上

Have fun with node.js. I absolutely love the platform :D

享受 node.js 带来的乐趣。我非常喜欢这个平台:D

回答by b_erb

Although your choice very much depends on the features you are going for, I really appreciate CouchDB for its native JavaScript environment. Both data and views are written in JavaScript so it fits very well to node.js in my opinion.

尽管您的选择在很大程度上取决于您要使用的功能,但我非常感谢 CouchDB 的原生 JavaScript 环境。数据和视图都是用 JavaScript 编写的,因此在我看来它非常适合 node.js。

There are also different client librariesavailable, some are rather low level, other really very abstracted.

还有不同的客户端库可用,有些是相当低级的,有些则非常抽象。

But as I said, you should also think about the features that you require for your database.

但正如我所说,您还应该考虑数据库所需的功能。

回答by J?kull

Redis is a popular choice. What you're after is a database driver that doesn't block.

Redis 是一个流行的选择。你所追求的是一个不会阻塞的数据库驱动程序。

The databases you listed are all very different. Redis takes the idea of key-value storages and runs with it, adding a variety of data types and ways of querying data. People often note that redis scales down very well too; meaning that it has very low overhead despite having the ability to perform.

您列出的数据库都非常不同。Redis 采用键值存储的思想并运行它,添加了多种数据类型和查询数据的方式。人们经常注意到 redis 也可以很好地缩小;这意味着尽管具有执行能力,但它的开销非常低。

Here is a list of available database modules: http://wiki.github.com/ry/node/modules#database

以下是可用数据库模块的列表:http: //wiki.github.com/ry/node/modules#database

回答by beatgammit

I really like CouchDB. It's a bit of a learning curve, but views are really powerful once you understand how to use them. There is a module called cradle on githuband npm that is really easy to work with. I haven't been able to test how fast it is, but it is really flexible (you can access your data in a browser too if you'd like).

我真的很喜欢 CouchDB。这是一个学习曲线,但是一旦您了解如何使用它们,视图就会非常强大。在 github和 npm有一个名为cradle的模块,它非常易于使用。我无法测试它的速度,但它非常灵活(如果您愿意,也可以在浏览器中访问您的数据)。

The major issue here is which database design makes sense for your application. Do you have data that is largely key-value in nature? If so, use Redis. Do you have data where not all documents necessarily have the same fields? If so, use a NoSQL database like CouchDB.

这里的主要问题是哪种数据库设计对您的应用程序有意义。您是否拥有本质上主要是键值对的数据?如果是这样,请使用Redis。您是否拥有并非所有文档都必须具有相同字段的数据?如果是这样,请使用像 CouchDB 这样的 NoSQL 数据库。

The next worse thing to using a blocking database is using the wrong database for your data. CouchDB is managed by Apache, so you know that it's good quality, but it doesn't make sense to use it if your data would make more sense in an SQL table or a simple key-value store.

使用阻塞数据库的下一个更糟糕的事情是为您的数据使用了错误的数据库。CouchDB 由 Apache 管理,因此您知道它的质量很好,但是如果您的数据在 SQL 表或简单的键值存储中更有意义,那么使用它就没有意义。

Think of your use case. Will you be more likely to want to do a full-text search, just get data by key, or get ranges of documents that have similar attributes?

想想你的用例。您是否更愿意进行全文搜索,只是通过键获取数据,还是获取具有相似属性的文档范围?

回答by Gary S. Weaver

Might want to check out Persistence, high level persistance/database system for node.js.

可能想查看Persistence,node.js 的高级持久性/数据库系统。

from thechangelog.com:

来自thechangelog.com

Persistence is a project to allow a high level API for persisting data between process runs. The goal is to support backends that are easy to use, powerful, flexible, or all of the above if possible.

Supported databases include:

  • PostgreSQL - An enterprise level relational database. The driver is implemented in pure JavaScript and communicates over TCP using the PostgreSQL wire protocol.
  • Sqlite3 - A simple, fast, server-less relational database. This driver is a wrapper around the command-line sqlite3 program. It requires sqlite3 to be in the path. The communication is extremely fast, but types aren't very precise. There are only strings and nulls returned.
  • MongoDB - A scalable, high-performance, open source, schema-free, document-oriented database. This driver also implements the wire protocol in JavaScript and communicated with the server over TCP.
  • JSON-DB - A homegrown system schema-free, document-oriented database that uses simple flat files containing JSON objects. This has no requirements at all except node and a filesystem. Performance is to be determined once it's implemented fully.

Persistence 是一个允许在进程运行之间持久化数据的高级 API 的项目。目标是在可能的情况下支持易于使用、功能强大、灵活或以上所有的后端。

支持的数据库包括:

  • PostgreSQL - 企业级关系数据库。该驱动程序是用纯 JavaScript 实现的,并使用 PostgreSQL 有线协议通过 TCP 进行通信。
  • Sqlite3 - 一个简单、快速、无服务器的关系数据库。该驱动程序是命令行 sqlite3 程序的包装器。它要求 sqlite3 在路径中。通信速度极快,但类型不是很精确。只返回字符串和空值。
  • MongoDB - 一个可扩展、高性能、开源、无模式、面向文档的数据库。该驱动程序还在 JavaScript 中实现了有线协议,并通过 TCP 与服务器通信。
  • JSON-DB - 一个自产的系统无模式、面向文档的数据库,它使用包含 JSON 对象的简单平面文件。除了节点和文件系统之外,这根本没有任何要求。一旦完全实施,就可以确定性能。

回答by fadedbee

Disclaimer: I'm the author.

免责声明:我是作者。

Perhaps have a look at BarricaneDBannounced here.

也许看看这里宣布的BarricaneDB

回答by qooleot

I'm not sure the correct solution is to solely focus on mapping a database to your web stack, but rather also considering application-specific requirements.

我不确定正确的解决方案是仅专注于将数据库映射到您的 Web 堆栈,而是还要考虑特定于应用程序的要求。

Are you analyzing twitter feeds or other high-volume data for patterns, but don't need transactional support? Then pick something really fast.

您是否正在分析 twitter 提要或其他大量模式数据,但不需要事务支持?然后选择一些非常快的东西。

Do you just want to store some really basic info in a few tables and its currently not an "enterprise focused" app? Then pick something cool to learn.

您是否只想在几个表中存储一些非常基本的信息,而它目前不是“以企业为中心”的应用程序?然后选择一些很酷的东西来学习。

Maybe you are going to store data thats really important to a client, robust, needs to be transactional, and have live replication to remote hosting facilities, etc. Then maybe look at something like postgresql. It wouldn't mirror as well, but the node.js driver works pretty well and if you aren't deathly afraid of sql it gets what you want in/out pretty easily.

也许你要存储对客户端非常重要的数据,健壮的,需要是事务性的,并且有实时复制到远程托管设施等。然后也许看看像 postgresql 这样的东西。它也不会镜像,但 node.js 驱动程序运行良好,如果您不是非常害怕 sql,它可以很容易地输入/输出您想要的内容。

As for my own opinion, I think going with a newer stack like node.js (vs traditional frameworks in php/java) is adding enough "new" complexity that one shouldn't add extra layers all at once. This is a good article that discusses that:

至于我自己的观点,我认为使用像 node.js 这样的新堆栈(与 php/java 中的传统框架相比)会增加足够的“新”复杂性,以至于不应该一次添加额外的层。这是一篇很好的文章,讨论了:

http://nodeguide.com/convincing_the_boss.html

http://nodeguide.com/convincing_the_boss.html

回答by PinkElephantsOnParade

I'll speak from my experience: CouchDB comes with a definite learning curve, whereas MongoDB I found to be very easy to learn and set up. I have never used redis. I suggest MongoDB - but that maybe shameless fanboyism - I have no numbers, heh, only claims of ease of use.

我将根据我的经验发言:CouchDB 具有明确的学习曲线,而我发现 MongoDB 非常容易学习和设置。我从来没有用过redis。我建议使用 MongoDB - 但可能是无耻的狂热分子 - 我没有数字,呵呵,只有易用性的要求。

回答by nponeccop

dirty is yet another flat-file key-value store. As the name suggests, it's a quick and dirty but performant solution for simple cases. I'm not the author :)

脏是另一个平面文件键值存储。顾名思义,对于简单的情况,它是一种快速、肮脏但高性能的解决方案。我不是作者:)

回答by Rob Tweed

Some more to consider:

还有一些需要考虑:

Globals: http://globalsdb.org

全球:http: //globalsdb.org

GT.M (see https://github.com/robtweed/node-mwirefor a starting point)

GT.M(有关起点,请参阅https://github.com/robtweed/node-mwire

M/DB (an open source clone of SimpleDB): https://github.com/robtweed/node-mdband you can use the Node.js SimpleDB client to access it: https://github.com/rjrodger/simpledb

M/DB(SimpleDB 的开源克隆):https: //github.com/robtweed/node-mdb,您可以使用 Node.js SimpleDB 客户端访问它:https: //github.com/rjrodger/simpledb