-1

I am thinking about using snake_case in my mongoDB-documents due to convention in the project. As I researched here, camelCase seems to be a standard in mongodb due to its BSON-storage.

My documents are for example

{
    "created_at": "",
    "issuer": "my-user-name",
    "document_id": "81234-guid",
    "file_id": "81234-another-guid",
    "details": {
       ...
    }
}

As you see, I under snake_case. That means that many of my field names are one char longer.

  • How does this affect the storage?
  • Is there any compression or algorithm, that stores field names separatly or is really each field name stored within the BSON?

In my use case the collection there will have many small entries For each document there will be about 10 entities stored in mongodb. There will be about 1.000.000.000 documents, meaning at least 10.000.000.000 entities stored in collection.

Steven
  • 61
  • 1
  • 3
  • 10
  • 1
    Use [$bsonSize()](https://docs.mongodb.com/manual/reference/operator/aggregation/bsonSize/) to check the size, then you can compare. – Wernfried Domscheit Nov 27 '20 at 17:49
  • I checked Object.bsonsize(db.coll.findOne()) - there is a difference of one byte showing the fact that the key really is stored in object – Steven Nov 29 '20 at 12:11

1 Answers1

1

The database does not prescribe how to name fields (other than there must be a field named _id).

In Ruby for example the convention is to use underscore style as you are contemplating.

If you want to use short field names for storage optimization, changing from camel case to underscore will be much less of a difference than actually using shorter field names (for example n instead of count, etc.).

D. SM
  • 13,584
  • 3
  • 12
  • 21
  • true about ruby, I edit my question to clarify. I thought there ia mongodb internal behaviour which factors out field names and use pointers... – Steven Nov 29 '20 at 12:12
  • Field names are stored with documents. See https://docs.mongodb.com/mongoid/master/tutorials/mongoid-documents/#aliasing-fields – D. SM Nov 29 '20 at 16:16