Govind Malviya
Govind Malviya

Reputation: 13763

Which schema would be good regarding performance

I am creating schema for MongoDB, I have two type of schema for Gender collection. I want to know which one would be better for Reading data (collection may contains millions record so I couldn't evaluate practically right now so please don't "say try on sample data")

one is array type :

"gender": [{
            "GenderType":M/F/U,
            "total:logins": 12,
            "totaluser": 20,
            "newuser": 11
     },
     {
           "GenderType":M/F/U,
           "total:logins": 12,
           "totaluser": 20,
           "newuser": 11
     },
     {
          "GenderType":M/F/U,
          "total:logins": 12,
          "totaluser": 20,
          "newuser": 11
     }
]

second is object type.

"gender": {
     "male": {
          "total:logins": 12,
          "totaluser": 20,
          "newuser": 11
     },
     "female": {
          "total:logins": 11,
          "totaluser": 10,
          "newuser": 10
     }
     "unknown": {
          "total:logins": 11,
          "totaluser": 10,
          "newuser": 10
     }
}

Priorities

  1. Performance
  2. Storage
  3. Maintainability

Upvotes: 1

Views: 75

Answers (1)

cirrus
cirrus

Reputation: 5672

When you say "reading" data, it may depend on the types of queries you wish to perform. Are you always reading whole documents, or do you intend to filter out gender types and perform maths functions on the contents? Arrays often will require MapReduce or the Aggregation framework to process for some types of query. That can be expensive on large collections, whereas working on collections of "female" objects can be written and processed more declaratively.

Can you elaborate on the kind of things you want to do with the data? You might get a more definitive answer.

Upvotes: 1

Related Questions