在GridFs中创建文件(MongoDb) [英] Creating file in GridFs (MongoDb)

查看:408
本文介绍了在GridFs中创建文件(MongoDb)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个集合,LogData和OptData。 LogData只有600条记录,而OptData有大约300万条记录。为了做一些逻辑数据,我试图合并两个colletion。但是简单地通过使用mongo命令合并创建大小大于16 MB的文档。



我可以使用GridFs合并文件吗?



我的集合像

  LogData 
[{
SId:10,
NoOfDaya:9
}
{
SId:11,
NoOfDaya:8
}]



OptData
[{
SId:10,
CId:12
}

{
SId:10,
CId 13
}]

我想要像

  LogData 
[{
SId:10,
NoOfDaya:9
OptData:[{
CId:12
},{
CId:13
}
]
}
{
SId:11,
NoOfDaya:8,
OptData:[]
}]

我可以通过使用mongodb find命令,但它创建的文档大小大于16 mb.Is使用mongodb GridFS可以做到这一点?


<你可以尝试将整个文档存储为JSON格式的文本字符串或BSON的二进制字符串在GridFS上,但这可能不是你想要的,因为当你将数据存储在GridFS中MongoDB将其视为无意义的数据块,并且无法对其执行任何有用的查询。



最好只是将数据归一化为两集合。当这导致一个特定的问题,你可以在一个新的问题描述这个问题。我们可以向您建议一个更切实可行的解决方案。


I have two collections, LogData and OptData. LogData is having just 600 records whereas OptData is having around 3 million records. To make some logical data, I am trying to merge both colletions. But merging simply by using mongo command create a document larger in size than 16 MB.

Can I merge files using GridFs?

My collections are like

   LogData
 [{
  "SId": 10,
   "NoOfDaya" : 9
  }
 {
 "SId": 11,
"NoOfDaya" : 8
}]



 OptData 
 [ {
     "SId": 10,
    "CId": 12
    }

{
"SId": 10,
 "CId": 13
   }]

I want something like

LogData
[{
  "SId": 10,
   "NoOfDaya" : 9
   "OptData" : [{
      "CId": 12
    },{
    "CId": 13
   }
   ]
  }
  {
      "SId": 11,
     "NoOfDaya" : 8,
     "OptData" : []
 }]

I am able to do this by using mongodb find command but it create document size larger than 16 mb.Is it possible to do this using mongodb GridFS?

解决方案

You could try to store the whole document as a text string of JSON or binary string of BSON on GridFS, but this is likely not what you want, because when you store data in GridFS MongoDB treats it as a meaningless blob of data and can not perform any useful queries on it.

It would be better to just keep the data normalized in two collections for now. When this causes a specific problem for you, you could describe this problem in a new question. We might be able to suggest you a more practicable solution.

这篇关于在GridFs中创建文件(MongoDb)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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