DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Data
  4. The New RavenDB 4.0 Attachments Feature

The New RavenDB 4.0 Attachments Feature

RavenDB now allows you to store binary data closely with documents in the database! Read on for more information on this new feature.

Oren Eini user avatar by
Oren Eini
·
May. 11, 17 · News
Like (2)
Save
Tweet
Share
2.18K Views

Join the DZone community and get the full member experience.

Join For Free

image

I previously wrote about the new attachments feature in RavenDB 4.0. Now, it is ready to be seen by outside eyes.

As you can see in the image on the right, documents can now have attached attachments (I’m sorry, couldn’t think of a better way to phrase this). This gives you the ability to store binary data inside RavenDB, but not as some free-floating value that has only very loose connection to the rest of the system. Those attachments are strongly tied to their parent document and allow you to store related information easily and right next to the document.

That also means that you can take advantage of RavenDB’s ACID nature and actually make modifications to both attachments and documents at the same time. For example, consider the following code:

public void AddProfilePicture(string userId, Stream profilePictureStream)
{
  var thumbnail = GenerateThumbnail(profilePictureStream);
  profilePictureStream.Position = 0;

  using(var session = store.OpenSession())
  {
        var user = session.Load<User>("users/123");
        session.Advanced.StoreAttachment(user, "profile-pic.jpg", profilePictureStream);
        session.Advanced.StoreAttachment(user, "profile-thumb.jpg", thumbnail);
        user.RegistrationStatus |= UserStatus.HasProfilePicture;
        session.SaveChanges();
  }

Here, we get the user’s profile picture, generate a thumbnail from it, and then associate both picture and thumbnail with the document. We are also updating the status of the user to indicate that they have a profile picture and then submit it all as one single transaction. That means that you don’t have to sync between different sources.

Attachments in RavenDB are also kept consistent through replication, so you won’t see partial results between nodes, and the attachments themselves are using de-duplication techniques to reduce the amount of storage that we take.

I’m really happy with this feature.

Document Profile (engineering) Replication (computing) Data (computing) Phrase (software) Advantage (cryptography) Connection (dance)

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Avoid “Schema Drift”
  • Tech Layoffs [Comic]
  • Core Machine Learning Metrics
  • Learning by Doing: An HTTP API With Rust

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: