How to insert HTML into Mongodb?

6,985 views
Skip to first unread message

m...@whiterabbitpress.com

unread,
Mar 7, 2013, 11:23:03 AM3/7/13
to mongod...@googlegroups.com
I read that it's "It's perfectly fine to store html files in MongoDB as standard utf-8 encoded strings" like <b>text</b>

But how do I do something like (attached) without getting kicked out of the editor because of escaping issues? I can't even paste it here for the same reasons. is there some standard function for encoding?


mongodb1.jpg
mongodb2.jpg

m...@whiterabbitpress.com

unread,
Mar 8, 2013, 12:41:02 PM3/8/13
to mongod...@googlegroups.com
not much of a community.

Francesca Krihely

unread,
Mar 8, 2013, 12:44:10 PM3/8/13
to mongod...@googlegroups.com
Hi Max

This StackOverflow question be helpful if you're trying to store an HTML Page/File


hope this helps!


--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

   

name     : "Francesca  Krihely", 
  title    : "Community Manager for MongoDB at 10gen",
  phone    : "347-474-6872",
  location : "New York, NY",
  twitter  : ["@francium", "@MongoDB""@10gen"],
  facebook : ["MongoDB", "10gen"] }

Max Hodges

unread,
Mar 10, 2013, 10:57:54 AM3/10/13
to mongod...@googlegroups.com
Thanks! Yes, I'm not sure how to just load data without using the shell. I guess just need to write a meteor app html one-page and a button so I can execute some script to do the import? Call me a noob as I'm just not sure how else to load data into mongodb except for the shell or a meteor app ...

On Sun, Mar 10, 2013 at 1:28 PM, Andrew Stephenson <andrew.s...@gmail.com> wrote:
Hi Max.

It looks like your html string is broken over new lines, which is what's causing problems for the shell. The same would need to be done if you were trying to insert a hardcoded html string via the driver rather than reading it from a file where the new lines would be escaped.

If you're set on doing this via the shell rather than  via a driver like Francesca suggested, you'll have to try build up the String over new lines like below before entering the string in to the shell.

db.test.insert({
    x:"<div id='product-description'><p>Who hasn't wished for a mini-R.... " +
"<p> <strong>Colors: </strong> White, Red, Orange and Blue <br> " +
" Runs on a single AA battery." +
" </p> <p>1575 yen</p> <!-- end #product-description --></div> "
})

I don't believe that there would be any way to read in a file within the shell as the ability to do so isn't a part of the javascript engine.
--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/vw00sM1v5o4/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Cheers!

Max Hodges
Founder/Director
White Rabbit Japan
http://whiterabbitjapan.com
03-6303-1840
090-1795-4446

Sam Millman

unread,
Mar 10, 2013, 11:49:01 AM3/10/13
to mongod...@googlegroups.com
99% of the time people are communicating to MongoDB from some kind of client side application, written in either Meteor or PHP or Java or something.

The shell is good at previewing things but it does have its limitations, or rather "shell" in general does since this is a shell thing not a mongo shell thing.


You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.

Ronald Stalder

unread,
Mar 10, 2013, 12:30:01 PM3/10/13
to mongod...@googlegroups.com
Hi Andrew

Em domingo, 10 de março de 2013 01h28min13s UTC-3, Andrew Stephenson escreveu:
Hi Max.

[ ... ]
 
I don't believe that there would be any way to read in a file within the shell as the ability to do so isn't a part of the javascript engine.

Yes, there is. It's not standard JavaScript, but there are a few OS commands built into the mongo shell, see "help admin".

So, you can do this (with your html in the file "test.html"):

> cat( "test.html" )
<div id="product-description">
    <p>Who hasn't wished....</p>
    <p>
        <strong>colors:</strong>
        White, Red,Orange, Blue
    </p>
</div><!--- end #product-description -->

> db.xx.insert({"x": cat("test.html")})
> db.xx.find()
{ "_id" : ObjectId("513cb33e854500fc6b7a4de6"), "x" : "<div id=\"product-description\">\n    <p>Who hasn't wished....</p>\n    <p>\n        <strong>colors:</strong>\n        White, Red,Orange, Blue\n    </p>\n</div><!--- end #product-description -->\n" }

Cheers, 
Ronald

Max Hodges

unread,
Mar 10, 2013, 1:05:27 PM3/10/13
to mongod...@googlegroups.com
Thanks guys! I'm new to Meteor and Mongodb too, but I'm really liking the architecture and making good progress. 
I have a history as a client/server application developer, so I never liked web development, as it felt like a huge step backwards in many ways. So when I first saw the Meteor video, I felt like this is the framework I'd been waiting for. 

And Mongodb too. I've worked as a MS SQL developer and admin for most of my career, so I was resistant to "re-train" and learn these new no-rel database systems. But after finally digging in and seeing what it's all about, I think it's brilliant. Still have a lot to learn to be more proficient. Thank you for pointing these things out to me.



--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/vw00sM1v5o4/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages