2

I have a little problem with my Thesis project.
I have a mongodb database with abour 400k entries styled like this:(i've translated the variables so if theres any typo, sorry);

var mongoose = require("mongoose");
var work_schema = new mongoose.Schema({
  worktype: String,
  ordernumber: String,
  art_code: String,
  qta: String,
  number_of_operatos: String,
  1_op_code: String,
  2_op_code: String,
  3_op_code: String,
  4_op_code: String,
  phase: String,
  notes: String,
  continued: String, //just a flag
  date_start: String, // DD-MM-YYYY
  date_end: String,   // DD-MM-YYYY
  time_start: String, //HH:MM:SS
  time_end: String,   //HH:MM:SS
  datainiziopart: String, //this is the date parsed like this YYYYMMDD i needed it for another purpose
  datafinepart: String, //this is the date parsed like this YYYYMMDD i needed it for another purpose
  cronsec: String,
  cronsec1: String,
  cronsec2: String,
  cronsec3: String,
  cronsec4: String,
  cronsec5: String,
  cronsec6: String,
  cronsec7: String,
  operationtimesec: String,
  designtimesec: String,
  totalecausalisec: String,
  ke: String,

  author: {
    id: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User"
    },
    username: String,
    codicereparto: {
      id: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "Reparti"
      },
      nomereparto: String,
      descrizionereparto: String
    }
  }
});
module.exports = mongoose.model("Work", work_schema);

As you can see the schema is not small at all, and having more than 400k entries, i need to query them when exporting/showing.
I used the limit function to show the latest entries.

I want to create a Page with a datepicker to query the data, or using the

date_start: String, // DD-MM-YYYY

or using the

datainiziopart // YYYYMMDD like <>=

Can you help me write the nodejs code to render a page with the result?

I use express if that can help. i tried to do this

router.get("/risultati", function(req, res) {
      Request.getAllRequestListingsCb(function (err, docs){
          res.render('pannello/risultati', { rL: docs });
      });
});


router.post("/ricercautente", function(req, res) {
  var data = req.body.filtro;
  var datadivisa = data.split(' - ');

  var datestart= moment(datadivisa[0], 'DD-MM-YYYY').format('DD-MM-YYYY');
  var dateend= moment(datadivisa[1], 'DD-MM-YYYY').format('DD-MM-YYYY');
  //res.redirect("/pannello/utentetutti");
  module.exports.getAllRequestListings = function (callback) {
      var query = {"datainizio": {"$gte": new Date(datainizio), "$lt": new Date(datafine)}};
      Lavori.find(query, callback);
  };
  res.redirect('pannello/risultati');

});


<div class="" align=center>
  <form  action="/ricercautente" method="post">
    <input type="text" name="filtro" id="filtro"  />
    <button class="pure-button pure-button-warning" name="" id="" type="submit">Submit</button>
  </form>
</div

and on another page

  <tbody>
      <% lavoritrovati.forEach(function(lavoro){ %>
      <tr>
        <td>          <%=lavoro.author.codicereparto.nomereparto%>        </td>
        <td>          <%=lavoro.tipodilavoro%>        </td>
        <td>          <%=lavoro.ordineproduzione %>        </td>
        <td>          <%=lavoro.codicearticolo %>        </td>
        <td>          <%=lavoro.quantita %>        </td>
        <td>          <%=lavoro.noperatori %>        </td>
        <td>          <%=lavoro.codoperatori%>        </td>
        <td>          <%=lavoro.codoperatori2%>        </td>
        <td>          <%=lavoro.codoperatori3%>        </td>
        <td>          <%=lavoro.codoperatori4%>        </td>
        <td>          <%=lavoro.fase %>        </td>
        <td>          <%=lavoro.note %>        </td>
        <td>          <%=lavoro.datainizio %>        </td>
        <td>          <%=lavoro.timestart %>        </td>
        <td>          <%=lavoro.datafine %>        </td>
        <td>          <%=lavoro.timeend %>        </td>
        <td>          <%=lavoro.continuato %>        </td>
        <td>          <%=lavoro.cronsec %>        </td>
        <td>          <%=lavoro.cronsec1 %>        </td>
        <td>          <%=lavoro.cronsec2 %>        </td>
        <td>          <%=lavoro.cronsec3 %>        </td>
        <td>          <%=lavoro.cronsec4 %>        </td>
        <td>          <%=lavoro.cronsec5 %>        </td>
        <td>          <%=lavoro.cronsec6 %>        </td>
        <td>          <%=lavoro.cronsec7 %>        </td>
        <td>          <%=lavoro.designtimesec %>        </td>
        <td>          <%=lavoro.operationtimesec %>        </td>
        <td>          <%=lavoro.ke %>        </td>
<% }); %>
TCC
  • 67
  • 1
  • 6
  • 2
    Please @Roman , review this. https://stackoverflow.com/help/how-to-ask You should provide at least a minimum verifiable example of your current code to solve it. We are not here to make other's homework, but we will be very glad of helping with your current code. May you paste it? – Alejandro Teixeira Muñoz Oct 03 '19 at 18:47
  • 1
    @AlejandroTeixeiraMuñoz sorry first time posting, if that can be helpful i can post a github copy, but most of the project uses italian variables or text so i was unsure if it can be helpful – TCC Oct 03 '19 at 19:02
  • 1
    It's not neccesary to post the full code. Post at least, your call to Express, and the main part of the HTML view/controller where you are using in the front, yes, this is a start point – Alejandro Teixeira Muñoz Oct 03 '19 at 19:04
  • 1
    The query for mongoose seems to be ok. Please show your call to Express function!! what are you sending? Are you sure the split functions are working as you expect?? – Alejandro Teixeira Muñoz Oct 03 '19 at 19:07
  • 3 opts: 1.- Make one api call for each "page", selecting the date and sending the date to the api, every call 2.- Make server side pagination - This means that the function in mongoose will select some part of the data, and will give it to you (https://stackoverflow.com/questions/43925662/mongoose-pagination-from-server-side) 2.- Make client side pagination - This means that the function in your front javascript, will be the one in charge of paginating: https://stackoverflow.com/questions/10816073/how-to-do-paging-in-angularjs What do you think is the best for you? – Alejandro Teixeira Muñoz Oct 03 '19 at 19:35
  • This last comment considers that you want to create like pages to navigate around the big results. If you need to create then the datepicker, tell me – Alejandro Teixeira Muñoz Oct 03 '19 at 19:37
  • if i understood correctly the client side pagination will load all my database and show only the requested ones. – TCC Oct 03 '19 at 19:39
  • Yep. It creates more "wait" time on the request response, but just one DB call, and is faster when later rendering it (as it is in memory loaded). The other one, on server, is just less heavier for the client. This is just your election/needs – Alejandro Teixeira Muñoz Oct 03 '19 at 19:40
  • I think you can try to measure the full response size in KB and this will give you an idea of the memory load you are creating on the web browser. If it's not too big.. go for it. (Angular UI Bootstrap - Pagination Directive) if under angular – Alejandro Teixeira Muñoz Oct 03 '19 at 19:42
  • if i use my datainiziopart: String, //this is the date parsed like this YYYYMMDD and use <>= greater, smaller or equal operators to fix my query? maybe its the moment date forman that creates query problem. I need to create this "one"page table so my chart js javascript code can read the data – TCC Oct 03 '19 at 19:44
  • You can check the exact parameteres you are sending on webinspectors from browsers https://developers.google.com/web/tools/chrome-devtools/open in network section – Alejandro Teixeira Muñoz Oct 03 '19 at 20:15
  • Did you make any progress ? (I'm working right now so I cannot be very very close, sorry) – Alejandro Teixeira Muñoz Oct 03 '19 at 21:15
  • Nope still still stuck.. Don't worry I'll. Figure it out – TCC Oct 04 '19 at 04:25

0 Answers0