Open In App

Difference between PostgreSQL and MongoDB

Last Updated : 03 Aug, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

1. PostgreSQL (Object-Relational Database) : 
PostgreSQL is a powerful, open source object-relational database management system (ORDBMS) with an emphasis on extensibility and standards compliance that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads. PostgreSQL is ACID-compliant, transactional, that stores the data in the tabular format and uses constraints, triggers, roles, stored procedures and views as the core components. 

Why use PostgreSQL ?  

  • Free and open source.
  • Available in multiple languages.
  • Highly Extensible.
  • Protects data integrity.
  • Builds fault-tolerant environments.
  • Robust access-control system
  • Supports international characters.
  • Apple uses PostgreSQL!

Writing queries in PostgreSQL: 
 

  • Creating students table 
     
 CREATE TABLE students (id INT, name VARCHAR (100)); 
  • Inserting a record into students table 
     
 INSERT INTO students VALUES (1, 'Geeks'); 
  • Reading records from the students table 
     
 SELECT * FROM students; 

 

 

  • Updating records in students table 
     
 UPDATE students SET name="GeeksforGeeks" WHERE id = 1; 
  •  

  • Deleting records from students table 
     
 DELETE FROM students WHERE id = 1; 

2. MongoDB (Cross-platform Document-Oriented Database) : 
MongoDB is a NoSQL database where each record is a document comprising of key-value pairs that are similar to JSON objects with schemas. MongoDB is flexible and allows its users to create schema, databases, tables, etc. Documents that are identifiable by a primary key make up the basic unit of MongoDB. Once MongoDB is installed, users can make use of Mongo shell as well. Mongo shell provides a JavaScript interface through which the users can interact and carry out CRUD operations. 

In other words we can say that MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era licensed under the Server Side Public License. 

Why use MongoDB? 
 

  • Scalable and can serve several machines.
  • It is JavaScript Based which makes it easier to use.
  • Has Faster response because it is a document-oriented database.
  • Simpler Environment Setup
  • It uses JSON syntax which is very easy to use and has a wide range of browser compatibility.
  • Data is stored in the form of JSON whether it is Objects, Object Members, Arrays, Values and Strings.
  • Uber and Stack Companies uses MongoDB!

Writing queries in MongoDB: 
 

  • Creating a student database 
     
 use student; 
  • Creating a students table 
     
 db.createCollection("students"); 
  • Inserting records into the students collection 
     
 db.students.insert 
(
    {
        "id" : 1,
        "Name" : "Harry",
                 "Team": "Geeks For Geeks"
    }
); 
  • Reading from the students collection 
     
 db.students.find({Name : "Harry"}).forEach(printjson); 

Difference between PostgreSQL and MongoDB : 
 

MongoDB PostgreSQL
MongoDB was written in C++ PostgreSQL was written in C
MongoDB was started in 2007 by 10gen, which created the product based on the word humongous PostgreSQL is an open-source project maintained by PostgreSQL Global Development Group and their prolific community
MongoDB offers the Community Support Forum, ServerFault, and StackOverflow. Users can also get enterprise support 24×7 via Enterprise grade support. PostgreSQL has a wide variety of community and commercial support options available for users. The Community support includes mailing lists and IRC
Non-Relational Database Management System Relational Database Management System
Document Oriented Object Oriented
Only Available in English Language Available in Multi Languages

Which is best and why? 

PostgreSQL is best when : You need Standard compliant, transactional and ACID (Atomicity, Consistency, Isolation and Durability) compliant out of the box which also has a wide support for NoSQL features. 

MongoDB is best when : You need Scalability and caching for real-time analytics but is not built for transactional data i.e., accounting systems.
 


Similar Reads

Difference between PouchDB and PostgreSQL
1. PouchDB : PouchDB is an open-source, NoSQL, in-line database. It is designed after CouchDB, which is a NoSQL database that powers npm. It is written in JavaScript language. There is no need to perform queries over the network as PouchDB resides inside the browser and thus it makes it extremely faster. It stores data locally using IndexedDB and W
2 min read
Difference between MySQL and PostgreSQL
A database is a collection of information that is structured in such a way that it is easy to manage and update. To make this task easier various Database Management Systems(DBMS) have been created. These include MySQL, PostgreSQL, MongoDB, Redis etc. 1. MySQL It is one of the most famous, open-source Relational database management systems (RDMS).
2 min read
Difference between MariaDB and PostgreSQL
1. MariaDB : MariaDB is an open source relational database management system (RDBMS) that is a compatible drop-in replacement for the widely used MySQL database technology. It is developed by MariaDB Foundation and initially released on 29 October 2009. MariaDB has a significantly high number of new features, which makes it better in terms of perfo
2 min read
Difference between SQLite and PostgreSQL
1. SQLite : SQLite is a software library that provides relational database management system (RDBMS). It was designed by D. Richard Hipp on August 2000. The design goals of SQLite were to allow the program to be operated without installing a database management system (DBMS) or requiring a database administrator. Some of the features of MySQL are -
3 min read
Difference between Couchbase and PostgreSQL
1. Couchbase : Couchbase Server is an open-source, distributed multi-model NoSQL document-oriented database software package that is optimized for interactive applications. It is also known as Membase. It was developed by Couchbase, Inc. and initially released in August 2010. 2. PostgreSQL : PostgreSQL is a powerful, open-source Object-relational d
2 min read
Difference between CouchDB and PostgreSQL
1. CouchDB : Apache CouchDB is an open-source document-oriented NoSQL database that uses multiple formats and protocols to store, transfer, and process its data, it uses JSON to store data, JavaScript as its query language using MapReduce, and HTTP for an API. It was developed by Apache Software Foundation and initially released in 2005. It is writ
2 min read
Difference between Cassandra and PostgreSQL
1. Cassandra : Cassandra is a free and open-source, distributed, wide column store, NoSQL database management system. It was developed by Apache Software foundation and initially released on July 2008. Cassandra is designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. 2.
2 min read
Difference between MS SQL Server and PostgreSQL
1. MS SQL Server : Microsoft SQL Server is a relational database management system (RDBMS) which is platform dependent and it is both GUI and command based software. It supports a wide variety of transaction processing, business intelligence and analytics applications in corporate IT environments. It was developed by Microsoft Corporation and initi
2 min read
Difference between InfluxDB and PostgreSQL
1. InfluxDB : InfluxDB is a time-series database and is known for its high availability and storage. It was developed by InfluxData in 2013. It is open-source licensed software and is widely used in retrieval of time series data. It is used in real-time analytics and monitoring of data. It does partitioning by sharding. InfluxDB is implemented in t
2 min read
Difference between Adabas and Alibaba Cloud AnalyticDB for PostgreSQL
1. Adabas : The Adabas stands for an Adaptable Database System. It was It was developed by Software AG to run on IBM mainframes. It was launched in 1971. It is an OLTP-DBMS for mainframes and Linux/Unix/Windows environments. Adabas is an enterprise database management system (DBMS) designed for reliability, high performance, scalability and low tot
2 min read
Article Tags :