two mongoose schemas are filter in one angular data table , but reference schemas is not filtering

two mongoose schemas are filter in one angular data table , but reference schemas is not filtering

samad Ullahsamad Ullah Posts: 3Questions: 1Answers: 0
edited June 25 in DataTables

two Schemas are mention below.


var schema = new Schema({
  baby_name: {type:String, default :''},
    baby_gender: {type:String, required:true},
  certificate_id: {type:String},
    baby_blood_group : {type:String},
    baby_weight : {type:String},
    baby_length : {type:String},
    time_of_birth : {type:String},
  patient_id : {type:mongoose.Schema.Types.ObjectId ,  ref: 'Patient'},
    life_status : {type:String} ,
  created_by : {
      ref : "User",
  updated_by : {
      ref : "User",
schema.plugin(timestamps,  {
  createdAt: 'created_at',
  updatedAt: 'updated_at'
module.exports = mongoose.model('birth_certificate',schema);**


var schema = new Schema({
  patient_id: { type: String },
  name: { type: String, required: true },
  relation: { type: String },
  age: { type: String },
  age_type: { type: String },
  blood_group: { type: String },
  cnic: { type: String },
  passport: { type: String },
  gender: { type: String, required: true },
  address: {
    city: { type: String },
    country: { type: String, required: true },
    location: { type: String },

  contact: {
    mobile_no: { type: String, required: true },
    whatsapp_no: { type: String },
    email: { type: String },

  invoice: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Invoice' }],
  status: { type: String, required: true },
  created_by: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "User",
    required: true

now i am sharing my birth-certificate.component.ts:

ngOnInit() {
    this.dtOptions = {
      pagingType: 'full_numbers',
      pageLength: 10,
      serverSide: true,
      processing: true,
      ajax: (dataTablesParameters: any, callback) => {
            dataTablesParameters, {}
          ).subscribe(resp => {
            console.log("the response data in ngoninit method is " , resp);
            this.certificateListData =;

              recordsTotal: resp.recordsTotal,
              recordsFiltered: resp.recordsFiltered,
              data: []
      columns: [{data:'patient_id.patient_id'},{data:''},{data:'baby_name'},{data:'baby_gender'},{data:'certificate_id'},{data:'life_status'},{data:'baby_weight'},{data:'baby_length'},{data:'baby_blood_group'},{data:'time_of_birth'}],


**now i am sharing my controller file " birth-certificateController.js" **

exports.index = function(req, res) {
  certificate_model.find({} , function(err , docs){
    console.log("The data is:" , docs);
      console.log("Error id :" , err);
        error: err
    var data = docs;


exports.dataTable = function(req,res){
    limit: req.body.length,
    skip: req.body.start,
    select : ('baby_name patient_id name baby_gender baby_blood_group life_status baby_weight baby_length time_of_birth relation certificate_id'),
    populate : ('patient_id'),
  //find:{ $or:[ {'status':'inactive'}, {'name':'farhan'} ]},
  search: {
      fields: ['patient_id.patient_id' ,'','baby_name','baby_gender','baby_blood_group','life_status','baby_weight']
    order: req.body.order,
    columns: req.body.columns
  }).then(function (table) {
    console.log("Data table response:" , res);


kindly suggest me how to filter my patient id in my data table , i am still working on it since last week but its not working ,,,
thanks in advance....

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.


  • allanallan Posts: 54,921Questions: 1Answers: 8,611 Site admin

    serverSide: true,

    This means that the server-side script is responsible for doing all the sorting, filtering and paging. DataTables will submit data to the server tell the server what it needs to do.

    I don't know what the code behind certificate_model.dataTables is, so I can't say why it wouldn't be doing the filtering, but that is where I suggest you start the debugging.


  • samad Ullahsamad Ullah Posts: 3Questions: 1Answers: 0

    Dear Allan!
    it is doing filtering but i want to filter reference Schema id knows as "patient_id", in my birth_certificate datatable here i am sending you a file , it will be clear

  • samad Ullahsamad Ullah Posts: 3Questions: 1Answers: 0

    kindly suggest any proper solution

  • allanallan Posts: 54,921Questions: 1Answers: 8,611 Site admin

    I'm afraid that writing server-side scripts for Mongoose is beyond the scope of the support that we can provide. If you can't sure how to query the database for the join type you want you might be best asking in a Mongoose specific forum.


Sign In or Register to comment.