Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 如何在规范化的nosql数据库中向上/向下引用多个级别?_Database_Nosql_Graphql_Data Modeling_Database Normalization - Fatal编程技术网

Database 如何在规范化的nosql数据库中向上/向下引用多个级别?

Database 如何在规范化的nosql数据库中向上/向下引用多个级别?,database,nosql,graphql,data-modeling,database-normalization,Database,Nosql,Graphql,Data Modeling,Database Normalization,我正在尝试建立一个数据库模型,它可以使用graphql的灵活性,但希望使其正常化 想象一下这种关系结构: planet continent country city continent: { continentName, //the id countries, //array of ids of countries cities //array of ids of cities } 但我想创建四个不同的集合来保持它的正常化 最好的描述是,它的模式如下所示:

我正在尝试建立一个数据库模型,它可以使用graphql的灵活性,但希望使其正常化

想象一下这种关系结构:

planet
  continent
    country
      city
continent: {
  continentName, //the id
  countries, //array of ids of countries
  cities //array of ids of cities
}
但我想创建四个不同的集合来保持它的正常化

最好的描述是,它的模式如下所示:

type Planet {
  planetName: String
}
type Continent {
  continentName: String
}
type Country {
  countryName: String
}
type City {
  cityName: String
}

type Query {
  planets: [Planet]
  continents: [Continent]
  countries: [Country]
  cities: [City]
}
很好,我可以查询每个单独的元素,并获得所有元素

但是如果我想得到一个大陆上所有的城市呢

我需要改进下一部分:

type Continent {
  continentName: String
  cities: [City]
}
type City {
  cityName: String
}
type Query {
  planets: [Planet]
  continents: [Continent]
  countries: [Country]
  cities: [City]
}
现在,如果我们进行查询,我们将获得
大陆名称
(id),我们可以获得所有属于它的城市。但我们需要在城市和大陆之间建立某种联系。我的想法是在数据库结构中做一些事情:

planet
  continent
    country
      city
continent: {
  continentName, //the id
  countries, //array of ids of countries
  cities //array of ids of cities
}
通过这种方式,我可以编写一个解析器,从查询的父对象中获取
cities
,并从指定id的cities集合中获取查询

但是如果我想做这样的事情呢:

type Query {
  cities(continentName: String): [City]
}
continent: {
  continentName, //the id
  planetName //id of the belonging planet
},
city: {
  cityName, //the id
  countryName, // id of the belonging country
  continentName, //id of the belonging continent
  planetName //id of the belonging planet
}
所以反过来说,把所有属于这个大陆的城市都找出来。我可以去查询特定的大陆,获取属于它的所有城市,并获取指定的城市,但这需要很长时间

如果我这样构造数据会怎么样:

type Query {
  cities(continentName: String): [City]
}
continent: {
  continentName, //the id
  planetName //id of the belonging planet
},
city: {
  cityName, //the id
  countryName, // id of the belonging country
  continentName, //id of the belonging continent
  planetName //id of the belonging planet
}
有了上面的结构,我就能够连接并以嵌套格式查询数据,无论从哪个级别往下查询多少级别,以及从哪个方向查询数据。这似乎是一个完美的解决方案,但正如我读过的noSQL数据库建模一样,我在任何地方都找不到它


解决方案是否存在任何可能的瓶颈或问题?

您试图解决的问题很难解决

我认为最好的方法是将问题分成多个较小的问题:

  • 创建一个描述世界区域的集合,区域将与WGS84坐标(或行星特定坐标系)的几何形状相关联

  • 创建一个像城市一样的
    兴趣点的集合,这些将只是WGS84坐标(有点像经度和纬度)

然后,您需要一种查询几何形状的相交、包含和并集的方法

您还需要能够判断一个点是否在形状中,以及在给定形状中有哪些点

将涉及一些动态规划,因为据我所知,宇宙中没有坐标系

查看PostGIS、GDAL和

祝你好运:)