0

I would like to store ticket details in an array in a mongo document. it works fine till the document size reaches 16MB, after that I get the exception (Resulting document after update is larger than 16777216) and program terminates abruptly. I cannot split this document coz it stores all the ticket details falls under that year 2016.

here goes my document structure.

{
   year:2016,
   purpose: ticketdetail,
   tickets:[
    {ticketid:001, desc:"xyz", created:20161231},
    {ticketid:002, desc:"xyz", created:20161231},
    {ticketid:003, desc:"xyz", created:20161231},
    .......
    .......
    {ticketid:00N, desc:"xyz", created:20161231},
   }]    
}
Dickson
  • 25
  • 1
  • 5
  • You can split 2016 document into document for each month, no ? – s7vr Mar 07 '17 at 18:26
  • @Veeram: This is yearly data where I will store tickets that falls under that respective year, same thing I have for monthly and daily as well. any idea without splitting the document?? – Dickson Mar 07 '17 at 18:30
  • @Dickson You will just have to split the document somehow. That 16MB limit is (for now at least) not optional. – Vince Bowdren Mar 07 '17 at 19:25
  • @VinceBowdren Thanks, do you any idea on storing the big documents using GridFS API? we can achieve this using GridFS but I could see the examples only to store BLOB (Multimedia) types using GridFS :) – Dickson Mar 08 '17 at 08:20

1 Answers1

2

You will need to split your document into separate documents, perhaps in a different collection. I would not recommend GridFS, because you cannot query data within a GridFS blob.

Here is a suggested document structure:

{
  _id: ObjectId("85bf0ef0b9692c0010978359"),
  "ticketid" : "001",
  "desc" : "xyz",
  "created" : ISODate("2016-12-31T00:00:00.000Z")
}
,
{
  _id: ObjectId("85bed4257726f90010d4e21f"),
  "ticketid" : "002",
  "desc" : "xyz",
  "created" : ISODate("2016-12-31T00:00:00.000Z")
}

Notes on this structure:

  1. Each ticket is in a different document - this makes it scalable, because there is no limit on the number of documents in a collection.
  2. The "created" field is now in a proper date field. This gives you more accurate queryability.
  3. You said that your original document was needed to store all tickets for 2016. A suitable query on this new collection will return you all tickets for 2016, so you don't need to store them all in a single document:
db.tickets.find({
    "created" : {
            $gte: ISODate("2016-01-01"),
            $lt: ISODate("2017-01-01")
        }
    }
});
Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56