# What is MongoDB? > Part of Prisma's Data Guide. The complete index is at https://www.prisma.io/dataguide/llms.txt. Learn about what MongoDB is and how it works. Canonical URL: https://www.prisma.io/dataguide/mongodb/what-is-mongodb Authors: Alex Emerich Content revision: 91b5ea3b95a0824bcd0e0d61f68d6121c6e45039fde2b5f874c4c65eec29030e Source revision: b6716699f6439c3ba6ae3bf7116b7da84963c978 ## What is MongoDB? MongoDB is an [open-source](https://github.com/mongodb/mongo) document-oriented [NoSQL](https://www.prisma.io/dataguide/intro/database-glossary#nosql) database system. Data is stored using JavaScript Object Notation(JSON)-like structures that can be specified at the time of data storage. Each document can have its own structure with as much or as little complexity as needed. MongoDB provides non-SQL methods and commands to manage and query data programmatically or interactively. MongoDB is known for its fast performance, scalability, and for enabling a rapid development pace. ## Origin story MongoDB was founded in 2007 by Dwight Merriman, Eliot Horowitz, and Kevin Ryan. They previously worked at an internet advertising company that was serving 400,000 ads per second. The team was developing many custom data stores to accommodate this traffic. They regularly ran into struggles around scalability and agility, which led to the inspiration to create a database that solved for these issues. And voila, MongoDB. ## How it works To achieve better scalability and agility, MongoDB works with the JSON variant, Binary JSON, or [BSON](https://www.prisma.io/dataguide/mongodb/mongodb-datatypes). BSON accommodates more data types than JSON, giving more flexibility to the types of data that can be stored in MongoDB. ### MongoDB data structure Rather than tables made up of [rows](https://www.prisma.io/dataguide/intro/database-glossary#row) and [columns](https://www.prisma.io/dataguide/intro/database-glossary#column), MongoDB has [collections](https://www.prisma.io/dataguide/intro/database-glossary#collections) made up of [documents](https://www.prisma.io/dataguide/intro/database-glossary#document). Documents are comprised of [field](https://www.prisma.io/dataguide/intro/database-glossary#field) and [value](https://www.prisma.io/dataguide/intro/database-glossary#value) pairs. In comparison to [relational databases](https://www.prisma.io/dataguide/intro/database-glossary#relational-database), the pieces that make up a MongoDB database can loosely be thought of as follows: | Relational | Document | | ---------- | ---------- | | Table | Collection | | Row | Document | | Column | Field | The basic structure looks as follows: ``` { field1: value1, field2: value2, field3: value3, ... fieldN: valueN } ``` Documents look very similar to a JSON object. Documents can hold any of the available BSON data types as well as other documents, arrays, and arrays of documents. This JSON-style format directly maps to native objects in most modern programming languages, making it a natural choice for developers. An example would look like: ``` var mydoc = { _id: ObjectId("5099803df3f4948bd2f98391"), name: { first: "James", last: "Joyce" }, birth: new Date('Feb 02, 1882'), death: new Date('Jan 14, 1941'), books: [ "Ulysses", "Dubliners","Finnegan's Wake" ], sales : NumberLong(1250000) } ``` - `_id` holds an \[_ObjectId_]. - `name` holds an _embedded document_ that contains the fields `first` and `last`. - `birth` and `death` hold values of the \[_Date_] type. - `books` holds an array of \[_strings_]. - `sales` holds a value of the \[_NumberLong_] type. Depending on the data model, rather than a single document housing all of the information on James Joyce and his work, a relational database could potentially have an `author` table and a `book` table that is joined with something like `author_id`. In this particular simple use case, the document model simplifies data access and keeps data that is accessed together, stored together. ### MongoDB document vs SQL table record Expanding on the previous example, let's look at how a document in MongoDB looks compared to the same record in a relational database. In a relational database, a table storing records might look something like this: ``` | primary_key | first_name | last_name | age | email | phone_number | | ----------- | ---------- | --------- | --- | -------------------- | ------------ | | 1 | Tom | Brown | 38 | tom.b@email.com | 555-3802 | | 2 | Sarah | Green | 84 | (NULL) | 555-8088 | | 3 | Sam | White | 22 | sammi@123.org | 555-1234 | ``` Whereas, as we saw with our author document previously, a collection of similar documents in MongoDB might be modeled in JSON like this: ``` { primary_key: 1, first_name: "Tom", last_name: "Brown", age: 38, email_address: "tom.b@email.com", phone_number: "555-3802" }, { primary_key: 2, first_name: "Sarah", last_name: "Green", age: 84, phone_number: "555-8088" }, { primary_key: 3, first_name: "Sam", last_name: "White", age: 22, email_address: "sammi@123.org", phone_number: "555-1234", notes: [ "High value customer", "Has a dog named Fido" ] } ``` Deciding on a document database versus a relational database comes down to the type of data that the database is storing and how it should be accessed. MongoDB's documents promote flexibility over rigidity and ease the way data is accessed from an application. ### MongoDB query language Since MongoDB databases are document-oriented, the data does not typically follow a pre-defined schema like a relational database. This makes accessing data different then when querying a relational database with structured query language (SQL). MongoDB has its own query language simply called MongoDB Query Language (MQL). Similar to SQL, MQL also allows a user to access data under certain specifications. You can control for returning documents that match criteria relevant to the need. We won’t go into the finer details of querying in MongoDB in this guide, but you can read more about it in our [querying in MongoDB guide](https://www.prisma.io/dataguide/mongodb/querying-documents). The basic syntax of a query in MongoDB will look something like this: ``` db..find() ``` To produce a nicer format for query results, you can use `.pretty()`. ``` db..find().pretty() ``` ## Conclusion MongoDB has become the most popular NoSQL database on the market. Developers enjoy working with MongoDB because of its ability to keep them working flexibly and with agility. MongoDB provides an alternative to the rigidity of relational databases and is better suited for applications with evolving schemas. Checkout out some of our other MongoDB content for in depth guides on [getting started with MongoDB, indexes, transactions, and more](https://www.prisma.io/dataguide/mongodb).