Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i send data from html to mongodb?

I am using node js with express and Mongo. I have a simple program that takes in user settings through radio buttons. I have a submit button but I do not know how to make it work from there. Do I need a new JS file to send it to mongodb? All I want is for my html to save the preferences and store them to the database. What steps do I start going in?

Example here: if I clicked male and hit submit, I would want the word male to save to the database.

<html>
  <body>
      <form action="">
        <input type="radio" name="sex" value="male">Male<br>
        <input type="radio" name="sex" value="female">Female
      </form>
  </body>
</html>
like image 561
user3579901 Avatar asked May 14 '14 17:05

user3579901


People also ask

How is data from website stored in MongoDB?

MongoDB stores the data on the disk as BSON in your data path directory, which is usually /data/db. There should be two files per collection there, collection. 0, which stores the data (and that integer is then incremented as needs be) and collection. ns which stores the namespacing metadata for the collection.

Can you upload files to MongoDB?

Step 1: Build a Node. JS Application. Step 2: Upload Your Files into FileU. Step 3: Storing Your Files in MongoDB through Grid FS.


1 Answers

First you want to send a http post to node js.

This will show you how to do that. How to retrieve POST query parameters?

Then you need to take that info and parse it and then send it to Mongo.

This will show you how to do an insert using Nodejs Mongo Driver. http://mongodb.github.io/node-mongodb-native/markdown-docs/insert.html

like image 66
Donny V. Avatar answered Oct 19 '22 13:10

Donny V.