Home > other >  How is a json actually stored in a noSql document database
How is a json actually stored in a noSql document database

Time:11-29

I am wondering how is a JSON stored in a NoSQL DB like MongoDb and others. If I were to store a JSON data in a SQL DB then I could chose to store it as a text(varchar) column. But then I would lose the benefits of a NoSQL DB. Does a NoSQL DB save JSON in a file? How does update of a field happen? Is the complete file read in memory, then updated and written back to the file?

CodePudding user response:

The broad answer -- especially because you say "MongoDB and others" -- is "in many ways, each probably unique to the database engine ingesting the JSON and into what target field type." Even most newer relational DBs have special performance and type handling for JSON data, the postgres jsonb column type being a notable standout. There is no easy, consistently applied answer here.

CodePudding user response:

Most NoSql databases save json as VARCHAR or STRING. Different NoSql databases use different strategy to save on disk. For example, Cassandra creates a file for each table. For every update, C* just appends the data in the file. There are processes like compaction where the data in file can gets compacted, for multiple rows of single primary key a single row gets saved in compaction process, compaction depends on timestamp of the row.

Update operations are always time and resource intensive. Most NoSql databases do not use update operation, an update operation can be internally turned in to a insert operation. That means, for a signal primary key, there can be multiple rows exist at a time. The compaction process takes care of merging multiple rows in to single row.

  • Related