dongyi1111 2013-09-01 00:58
浏览 63

如何格式化并将这些JSON变量插入Mongodb,以便可以使用jQuery / AJAX / PHP访问它们?

I have a huge javascript file that reads sort of like this:

var MyVariable1 = [ { 
  ThingsToGet: [ 
  { 
     first_thing: "SOMETHING ONE",
     second_thing: [[1, 0], [2, 0], [3, 4], [4, 4], [5, "x"], [6, "x"]]
     third_thing: 0,
     fourth_thing: []
     },{ 
     first_thing: "SOMETHING TWO",
     second_thing: [[1, 0], [2, 5], [3, 4], [4, 4], [5, "x"], [6, "x"]],
     third_thing: 0,
     fourth_thing: []
     },{ 
     first_thing: "SOMETHING THREE",
     second_thing: [[1, 0], [2, 0], [3, 4], [4, 4], [5, 2], [6, 2]],
     third_thing: 0,
     fourth_thing: []
     },
   ]
   }
 ];


 var MyVariable2 = [ { 
     ThingsToGet: [ etc, etc, etc...

I'd like to shove all of that into a MongoDB database and have the client just grab the variables he/she needs via AJAX so they won't have to download the whole file. An additional reason is the data in the file is also semi-sensitive so it would also be nice if it couldn't be downloaded directly.

Just to make it a little harder, I also need to use Underscore.js to combine the 'MyVariables' like so:

var CombinedVariables = _.union(MyVariable1, MyVariable2);

I've seen this example: http://media.mongodb.org/zips.json but I don't know if in my case whether each 'MyVariable' variable should be a separate document or collection or what.

And as I'm typing this I'm starting to wonder if this is possible at all, it would have to work like this:

var CombinedVariables = _.union(MyVariable1, MyVariable2);  
//both variables are stored in mongo, keep in mind there are thousands of them


 for (var i = 0; i < CombinedVariables.length; ++i) { blah blah blah };
//we do some things with each variable 

Somewhere in there would have to be an Ajax function to get the variables, but I'm not sure where and I'm not even sure if it's possible to do it that way.

So to sum up: I'm new to JSON, AJAX & MongoDB, I don't know how to format the JSON, I don't know how to fetch the variables and I don't know if this is possible or even worth trying.

ps I'm using PHP server-side, possibly with this Mongo REST server thing which looks interesting: https://github.com/joevallender/slim-php-mongo-rest

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)