嗨,朋友,我的数据库中有这个架构
const impresionSchema = mongoose.Schema({
id:{type:Number, required: true},
ap:{type:String, required: true},
mac_address:{type:String, required: true},
campaniaId:{type:String, required: true}
}, {versionKey: false});
这是我对数据库的查询
router.get("/:start/:end", (req, res, next) => {
const start = parseInt(req.params.start);
const end = parseInt(req.params.end);
const unique = req.query.unique !== undefined;
Impresion.find({id:{$gte:start, $lte:end}}).then(impresiones => {
res.status(200).json({
message: "Impresiones fetched successfully!",
impresiones: impresiones
});
});
});
Mongo不返回任何数据,但是根据查询有多个文档
**对不起我的英语
答案 0 :(得分:0)
像这样使用它:
Impressions.find({id:{$gte:start, $lte:end}}).toArray().then(arr => {}).catch()
答案 1 :(得分:0)
我认为您错过了导出模式,因此导出模式如下:-
var mongoose = require('mongoose');
var db = mongoose.createConnection(your hostname, you database name');
const impresionSchema = mongoose.Schema({
id:{type:Number, required: true},
ap:{type:String, required: true},
mac_address:{type:String, required: true},
campaniaId:{type:String, required: true}
}, {versionKey: false});
var Impresion = db.model('Impresion', impresionSchema);
module.exports = Impresion; // this is what you want