Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1026953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:09:49+00:00 2026-05-16T12:09:49+00:00

I’m working on a project where I’m looking to store raw svg data inside

  • 0

I’m working on a project where I’m looking to store raw svg data inside my mongodb. Right now, it appears a bit goofy because I need to escape the svg string like so:

{ "_id" : ObjectId("4c61e60d4d02da615f175b6e"), "name" : "Triangle", "svg-data" : "<?xml version=\"1.0\" encoding=\"utf-8\"?> <!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363) --> <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> <svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" width=\"63.781px\" height=\"85.042px\" ... bunch of data elided here ... </svg>" }

This is somewhat acceptable but then I may need to de-escape (is that a word?) or decode on the client side once the json is passed back down from the server.

I’m curious if anyone else is doing this (I couldn’t find any examples on google or stack overflow) and/or if there is any advice on the best way to do this (or a better way to do it).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:09:49+00:00Added an answer on May 16, 2026 at 12:09 pm

    Personally I haven’t stored files in MongoDB yet, but according to mongodb.org it’s quite efficient to store files in the database. Storing files in the database gives you the following advantages:

    • Because the files are chunked, you can fetch only part of a file. Useful for objects such as video, not so much for SVG.
    • All of your files are replicated together with your database, so you don’t have to set up a separate replication system just for your files.

    Now, the thing that seems to be holding you back is escaping the data. However, you only have to escape the SVG data if you manually type statements into the MongoDB shell. If you’re using a driver to interact with the database, the driver will take care of escaping special characters in the data. When you read out the data in your code, the driver will also unescape the data for you.

    An example to demonstrate, in the MongoDB shell:

    var myObject = { "myKey": "Data with \"special\" characters." }
    print(myObject.myKey)
    

    In the first line I have to escape the quotes, because I manually type the statement. The MongoDB drivers will do this for you if you interact with the database from code.

    The print() statement automatically unescapes the data, so the output will be:

    Data with “special” characters.

    Database drivers will also unescape strings automatically. If you send a JSON object to the client’s browser and read out the values with JavaScript, the browser will also unescape the data.

    When you manually prepare the data for insertion, you will have to escape special characters, there’s no way around it. But as soon as you interact with the database from code, the database drivers will take care of this and you won’t have to worry about it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.