I
I
irvdev2016-10-19 22:38:55
JavaScript
irvdev, 2016-10-19 22:38:55

How to add custom fields to MongoDB collection?

Hello! I ran into a problem that I don't know how to add custom fields to the collection.
In general, the essence is as follows.
I am writing an application for honey. document flow. There is a collection of patients, they have default fields. for them I created a model

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var schema = new Schema({
  firstName: {type: String},
  lastName: {type: String},
  email: {type: String},
  phone: {type: String},
  adress: {type: String}
});

module.exports = mongoose.model('Patient', schema);

Implemented the output of patients in the table. Also adding, editing, deleting.
afec76162a8a40aa80168b858d95919d.png
Next, I created a custom fields model
var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var schema = new Schema({
  inputName: {type: String}
});

module.exports = mongoose.model('Input', schema);

Also made the output of custom fields. Adding, deleting, editing.
c71eb714bd8547be86cd509b14a3e7d4.png
Next, I want to display these fields in the patient's chart. So that data from these fields is written to the documents of patients.
e97e6426c7c34d25a4d420b229a8b823.png
But something I don’t know at all how to do it on mongo, is it possible to implement this? I would be grateful for any construct.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
irvdev, 2016-10-20
@irvdev

It seems I figured it out myself!)) I made two queries to the database through async and brought it all into a template.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question