I have a mongo db schema like so
users:
{username:"",
age: "",
data: [
{field1:"", field2:""},
{field1:"", field2:""}
]
}
My problem is how do send over my user object to my express route to post data to the db.
Typically i create my user object like so:
var user= {username:"test" age: 20};
and send this user object with my ajax call to my adduser route.
Ho do i structure my above assignment to include my embedded documents.
when i use this structure:
sign_in_data: [{date:"",time_in:"",time_out:""}]
my database looks like this:
sign_in_data[0][date]: "",
sign_in_data[0][time_in]: "",
sign_in_data[0][time_out]: ""
but it should look like this:
sign_in_data: [
{
date: "2015-06-08",
time_in: "17:35",
time_out: "17:35"
},
]
at the moment when you are configuring express, review if you are using this line of code:
In case you are using Express 4.x version
Note: you need to have body-parser installed.
In case you are using Express 3.x version
I did a test example where the property cars is an an array of objects send from the html file, and it is saving as you want in the database.
So this is my express server file:
database data inserted:
and my html file where I am sending the data, you can review it in this gist file: https://gist.github.com/wilsonbalderrama/62f76a348c0aa217cdd9
Hope this helps you.