Node.js 使用Mongoose从NodeJS Api检索许多结果(重复)
我正在用NodeJS和Mongoose构建一个API Rest。我检索视图文档的索引功能如下:Node.js 使用Mongoose从NodeJS Api检索许多结果(重复),node.js,mongodb,mongoose,mongoose-schema,Node.js,Mongodb,Mongoose,Mongoose Schema,我正在用NodeJS和Mongoose构建一个API Rest。我检索视图文档的索引功能如下: const Views = require('../models/views.model'); module.exports = { async index(req,res){ const views = await Views.find({}); res.json(views); } } 我的想法是这样的: const mongoose = req
const Views = require('../models/views.model');
module.exports = {
async index(req,res){
const views = await Views.find({});
res.json(views);
}
}
我的想法是这样的:
const mongoose = require('mongoose');
var Schema = mongoose.Schema;
const DataSchema = new Schema({
personId: Schema.Types.ObjectId,
campaignId: Schema.Types.ObjectId,
watchedMinutes: Number
});
const views = mongoose.model('Views', DataSchema);
module.exports = views;
数据库中只有50个文档,但当我从失眠中打电话时,我得到了17600个。我做错了什么
提前谢谢