从数据库存储和查询JSON [英] Storing and querying JSON from a database

查看:306
本文介绍了从数据库存储和查询JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说过MongoDB,但我不确定我是否完全理解这个概念。

I've heard about MongoDB, but I'm not sure I fully understand the concept.

如果我有多个JSON对象存储在MongoDB中:

If I have multiple JSON objects stored in MongoDB:

[{"id": "peter",
  "age": "12",
  "gender": "male"},
 {"id": "gemma",
  "age": "12",
  "gender": "female"},
 {"id": "paul",
  "age": "13",
  "gender": "male"}]

如何查询所有JSON对象 age> = 12

How would I be able to query all JSON objects with age >= 12?

推荐答案

JSON只是一种序列化技术。在本身,这个序列化方法可能不应该确定你的持久性介质。看看你的问题,看起来你正在寻找的是一个典型的关系存储数据库,您可以使用SQL以灵活的方式查询您的数据。

First of all, understand that JSON is just a serialization technique. In and of itself, this serialization method probably should not determine your persistence medium. Looking at your question on the surface, it seems like what you are looking for is a typical relational storage database where you can use SQL to query against your data in a flexible manner.

序列化/反序列化JSON数据,以便在从这样的关系数据库中检索之后存储到或呈现在几乎任何编程语言中都是微不足道的。

Serializing/deserializing JSON data for storage into or for presentation after retrieval from such a relational database is trivial in pretty much any programming language.

现在,如果真的需要存储各种不真正具有固定结构的JSON文档(或任何其他类型的文档)的片段,这是真正当你通常会开始看一个NoSQL类型的解决方案,如MongoDB。使用更流行的NoSQL数据库的另一种可能的情况是,当您处理大量数据并需要水平扩展(即数据太大,您需要在多个服务器上扩展数据库)。许多NoSQL系统使这比传统的关系数据库更容易做。当然,在这种情况下,您需要根据它们提供的功能来评估这些工具,以允许您以最有用的方式为您的用例读取,写入和查询数据。

Now if you truly need to store various snippets of JSON documents (or any other sort of document) that don't really have a fixed structure, that is really when you typically would start looking at a NoSQL type of solution such as MongoDB. One other possible such scenario for using the more popular NoSQL databases is when you are dealing with massive amounts of data and need to scale horizontally (i.e. the data is so large you need to scale the database across multiple servers). Many NoSQL systems make this much easier to do than traditional relational DB's. Of course in such a scenario, you would then need to evaluate those tools based on the functionality they provide in allowing you to read, write, and query data in the most useful manner for your use case(s).

这篇关于从数据库存储和查询JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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