MongoDB Json 文档结构
MongoDB Json document structure
我正在使用 MEAN 创建网络应用程序。我正在查看 AngularJS 教程,他们有一个很大的 JSON 文件,其中包含所有产品,然后每个产品都有单独的 JSON 文件。
link: https://docs.angularjs.org/tutorial/step_08
如果我正在使用 MongoDB 并拥有此数据。
"title: Grand Theft Auto V",
"genre": "Genre: Action, Adventure",
"developer": "Developer: Rockstar North",
"releasedate": "Release Date: 2015. April 14. (PC)",
"publisher": "Publisher: Rockstar Games ",
"rcpu": "Intel Core i5 3470 @ 3.2GHZ (4 CPUs) / AMD X8 FX-8350 @ 4GHZ",
"rram": "8GB",
"rgpu": "NVIDIA GTX 660 2GB / AMD HD7870 2GB",
"directx": "12",
"operatingsystem": "Windows 7 ",
"storage": "65GB",
"mcpu": "Intel Core 2 Quad CPU Q6600/AMD Phenom 9850 Quad-Core Processor",
"mgpu": "NVIDIA 9800 GT 1GB / AMD HD 4870 1GB",
"ram": "4GB"
我想要一个所有带标题的游戏的列表,然后单击一次加载系统要求。
存放数据的最佳方式是什么?
谢谢。
首先,您可以按照 this post 为您的游戏创建 REST API。
现在您需要游戏列表的数据。为此,您可以执行以下操作:
db.collection('games').find({}, {title: 1}, function(err, games){
if(err) console.log("Error: " + JSON.stringify(err));
if(games) res.json(200, games);
});
现在这将为您 return 游戏列表 title
及其 _id
字段。
其次,您需要有关游戏的详细信息。您可以通过 _id
字段查询 games
集合来获得。像这样:
db.collection('games').findOne({_id: game_id_from_request_params}, function(err, game){
if(err) console.log("Error: " + JSON.stringify(err));
if(game) res.json(200, game);
});
这将为您提供有关特定游戏的详细信息,包括所有系统要求。
希望对您有所帮助。
我正在使用 MEAN 创建网络应用程序。我正在查看 AngularJS 教程,他们有一个很大的 JSON 文件,其中包含所有产品,然后每个产品都有单独的 JSON 文件。
link: https://docs.angularjs.org/tutorial/step_08
如果我正在使用 MongoDB 并拥有此数据。
"title: Grand Theft Auto V",
"genre": "Genre: Action, Adventure",
"developer": "Developer: Rockstar North",
"releasedate": "Release Date: 2015. April 14. (PC)",
"publisher": "Publisher: Rockstar Games ",
"rcpu": "Intel Core i5 3470 @ 3.2GHZ (4 CPUs) / AMD X8 FX-8350 @ 4GHZ",
"rram": "8GB",
"rgpu": "NVIDIA GTX 660 2GB / AMD HD7870 2GB",
"directx": "12",
"operatingsystem": "Windows 7 ",
"storage": "65GB",
"mcpu": "Intel Core 2 Quad CPU Q6600/AMD Phenom 9850 Quad-Core Processor",
"mgpu": "NVIDIA 9800 GT 1GB / AMD HD 4870 1GB",
"ram": "4GB"
我想要一个所有带标题的游戏的列表,然后单击一次加载系统要求。
存放数据的最佳方式是什么?
谢谢。
首先,您可以按照 this post 为您的游戏创建 REST API。
现在您需要游戏列表的数据。为此,您可以执行以下操作:
db.collection('games').find({}, {title: 1}, function(err, games){
if(err) console.log("Error: " + JSON.stringify(err));
if(games) res.json(200, games);
});
现在这将为您 return 游戏列表 title
及其 _id
字段。
其次,您需要有关游戏的详细信息。您可以通过 _id
字段查询 games
集合来获得。像这样:
db.collection('games').findOne({_id: game_id_from_request_params}, function(err, game){
if(err) console.log("Error: " + JSON.stringify(err));
if(game) res.json(200, game);
});
这将为您提供有关特定游戏的详细信息,包括所有系统要求。
希望对您有所帮助。