Я настраиваю маршрут для возврата определенной вещи из коллекции вещей, используя findOne и идентификатор объекта вещи в качестве параметра. почему результат не возвращает только одну совпавшую вещь?
Я попытался найти findOne с идентификатором в качестве параметра
Вот схема вещи
const mongoose = require("mongoose");
const thingSchema = mongoose.Schema({
title: { type: String, required: true },
description: { type: String, required: true },
imageUrl: { type: String, required: true },
userId: { type: String, required: true },
price: { type: Number, required: true }
});
module.exports = mongoose.model("Thing", thingSchema);
найти маршрут маршрута
app.get("/api/stuff/:id", (req, res, next) => {
Thing.findOne({
_id: req.params.id
})
.then(thing => {
res.status(200).json(thing);
})
.catch(error => {
res.status(404).json({
error: error
});
});
});
Я ожидал, что результат /api/stuff/:5d9834968e23a32580a1751b
будет:
{
"_id": "5d9834968e23a32580a1751b",
"title": "tecno camon 8",
"description": "quality condition",
"imageUrl": "https://i0.wp.com/www.techslize.com/wp-content /uploads/2017/02/Tecno-camon-c8-black.png?resize=407%2C450&ssl=1",
"price": 3000,
"userId": "userID40282382",
"__v": 0
}
, но фактический результат - целая коллекция.