- Notifications
You must be signed in to change notification settings - Fork 542
Open
Description
i got empty json when access get to :http://localhost:3000/orders
{
"count": 0,
"orders": []
}
order.js :
const mongoose = require('mongoose'); const orderSchema = mongoose.Schema({ _id: mongoose.Schema.Types.ObjectId, product: {type:mongoose.Schema.Types.ObjectId, ref:'Product', required: true}, quantity: {type:Number, default:1} }); module.exports = mongoose.model('Order',orderSchema) getroutes :
router.get('/', (req,res,next)=>{ Order.find() .select("product quantity _id") .populate('product') .exec() .then(docs => { res.status(200).json({ count: docs.length, orders: docs.map(doc => { return { _id :doc._id, product: doc.product, quantity: doc.quantity, request: { type: 'GET', url: `http://localhost:3000/orders/${doc._id}` } }; }) }); }) .catch(err => { res.status(500).json({ error: err }); }); }); Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels