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 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图