Collections query with find method and render to ejs

Viewed 19

I have operator Collection in mongoDB. And I want to get all information in ejs table so I wrote below codes. But I get error with operators.forEach is not a functions How can I solve this problem ?

This is Collection model:

const operatorSchema = new Schema({
    operatorName: {
        type: String
    },
    productsSerialNumber:[{productSerialNumbers: String}],
    operatorSerialNumber: {
        type: Number
    },
    users:[{
        email:String,
        payment:Number,
        paymentsData: Date,
      }],
    operatorState:{
        type: Boolean,
    }

});

And this is the query function:

exports.getOperatorInformations = (req, res, next)=>{
 
    

    Operators.find({},function(err,docs){
        docs.forEach(function(dataCatch){
            console.log(dataCatch.users)
            res.render('home',{operators: dataCatch});

        })
     })    
    }
}

And ejs file part:

      <% operators.forEach(function(data){ %>
                                    <tr>
                                    <td>
                                        <%=  data.operatorName %>
                                     </td>
                                     <td>
                                        <%=  data.productsSerialNumber %>
                                     </td>
                                     <td>
                                        <%=  data.productsSerialNumber %>
                                     </td>
                                     <% })%>

                                     <% data.users.forEach(function(data){ %>
                                    <td>
                                       <%=  data.users.email %>
                                    </td>
                                    <td>
                                        <%=  data.users.paymentsData %>
                                     </td>
                                    <td>
                                        <!-- <%=  data.users.payment %> -->
                                     </td>
                                     </tr>
                                <% })%>
                                
                                 </tr>
0 Answers
Related