我的论文项目有点问题。
我有一个 mongodb 数据库,其中包含约40万个条目,其样式如下:(我已经翻译了变量,所以如果有错字,抱歉);
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);
如您所见,架构根本不小,并且有超过40万个条目,在导出/显示时我需要查询它们。
我使用了限制功能来显示最新条目。
我想用日期选择器创建一个页面来查询数据,或者使用
date_start:字符串,// DD-MM-YYYY
或使用
datainiziopart // YYYYMMDD,例如<> =
您能帮我编写 nodejs 代码来呈现结果页面吗?
如果可以,我会使用快递。 我试图这样做
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
和另一页
<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>
<% }); %>