Starting With the Basics
RavenDB is a mature, multi-platform, NoSQL document-oriented database, safe by default and optimized for efficiency. It is easy to learn and use with several languages — including C#, Java, Python, NodeJS, Ruby, and C++. Being fully transactional, RavenDB supports the best features from NoSQL and the relational world.
With RavenDB, you can achieve 150,000 writes per second and more than one million reads on commodity hardware. It offers a rich integrated GUI available for any license, including a free Community version.
This Refcard is intended to help you get the best results from RavenDB, starting from the basics.
- For installation guidance, see https://ravendb.net/docs/article-page/4.1/csharp/start/installation/setup-wizard
- For a self-directed free learning course, see https://ravendb.net/learn/bootcamp
- For an in-depth reference, see https://ravendb.net/articles/inside-ravendb-book
Creating Your First Database
After installing RavenDB, you can use the Management Studio to easily create your first database.
To create your first database:
- Select the Database option in the left panel
- Click on the New Database button
- Type a name for the new database
- Click on the Create button
Also, RavenDB provides you with sample data for learning purposes. To load it:
- Select Databases on the left panel
- In the right panel, click on the name of the database you just created
- In the left panel, click on Settings, and then Create Sample Data
- Click on the big Create button
The sample data comes from the Northwind database. Originally the sample database that came with SQL Server, it has been used for decades as the sample database in the Microsoft community. If you are new to the NoSQL world, this is a valuable resource to learn about NoSQL database modeling.
Going to the Documents section (left panel), you will see the sample data that was loaded into your database.
Understanding the Document Concept
A document is a self-describing, hierarchical tree data structure that can consist of maps, collections, and scalar values. RavenDB documents are created with simple JSON.
For example, assuming that you loaded the sample data into a database, you could use the Go to document feature (the text box in the Studio toolbar), to go to the document orders/101-A.
{
"Company": "companies/86-A",
"Employee": "employees/4-A",
"Freight": 0.78,
"Lines": [
{
"Discount": 0.15,
"PricePerUnit": 14.4,
"Product": "products/1-A",
"ProductName": "Chai",
"Quantity": 15
},
{
"Discount": 0,
"PricePerUnit": 7.2,
"Product": "products/23-A",
"ProductName": "Tunnbröd",
"Quantity": 25
}
],
"OrderedAt": "1996-11-07T00:00:00.0000000",
"RequireAt": "1996-12-05T00:00:00.0000000",
"ShipTo": {
"City": "Stuttgart",
"Country": "Germany",
"Line1": "Adenauerallee 900",
"Line2": null,
"Location": {
"Latitude": 48.7794494,
"Longitude": 9.1852878
},
"PostalCode": "70563",
"Region": null
},
"ShipVia": "shippers/2-A",
"ShippedAt": "1996-11-15T00:00:00.0000000",
"@metadata": {
"@collection": "Orders",
"@flags": "HasRevisions"
}
}
As you can see, you can aggregate related information into a common object, as in the case of the ShipTo property, which has all the shipping information. Also, you can reference other documents (as in the ShipVia property).
In a document-oriented database, documents are organized in collections.
Understanding the Collection Concept
Collections provide a good way to establish a level of organization. For example, documents holding customer data are very different from documents holding product information, and you want to talk about groups of them. RavenDB allows for a document to be stamped with a string value that will be evidence of its type (like “Customers” and “Products”).
Documents that are in the same collection can have completely different structures. Because RavenDB is schemaless, this is fine.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}