Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

collections - Creating file in 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...