title: How insert one-to-one, one-to-many relationship using nodejs with mongoDB
body: <p>I have two collections in my database those are following</p>
  
  <ol>
  <li>student</li>
  <li>course</li>
  </ol>
  
  <p>I want to insert data's like <code>one-to-one</code>, <code>one-to-many</code> relationship.</p>
  
  <p><strong>example</strong></p>
  
  <p>Am sent following data's in my <code>form-data</code></p>
  
  <ol>
  <li>name</li>
  <li>email </li>
  <li>phone</li>
  <li>password</li>
  <li>course_name</li>
  <li>course_cost</li>
  </ol>
  
  <p>The above data's <code>name</code>, <code>email</code>, <code>phone</code>, <code>password</code> stored in <strong>student</strong> table. </p>
  
  <p>And <code>course_name</code>, <code>course_cost</code> stored to <strong>course</strong> table with <code>student_id</code>.</p>
  
  <p>This is my code:</p>
  
  <p><code>route/students.js</code></p>
  
  <pre><code>const express = require('express');
  const path = require('path');
  const config = require('../config/database');
  
  
  const router = express.Router();
  
  let Student = require('../models/student_model');
  
  router.post('/add_student', function(req, res){
      let data = new Student();
      data.name = req.body.name;
      data.email = req.body.email;
      data.phone = req.body.phone;
      data.password = req.body.password;
  
      data.save(function(err, data){
          if(err) throw err;
          res.send(data);
      });
  
  });
  
  module.exports = router;
  </code></pre>
  
  <p><code>models/student_model.js</code></p>
  
  <pre><code>const mongoose = require('mongoose');
  
  let StudentSchema =  mongoose.Schema({
      name:{
          type: String
      },
      email:{
          type: String
      },
      phone:{
          type: String
      },
      password:{
          type: String
      },
  
      }, { collection: 'student' });
  
  
  const Student = module.exports = mongoose.model('Student', StudentSchema);
  </code></pre>
  
  <p>This is my API call:
  <a href="https://i.stack.imgur.com/gGy1M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gGy1M.png" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>My above code am done store student data stored in <code>student</code> table, but i don't know how to add one-to-one relationship </p>
  </blockquote>