You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Return model
module.exports = restful.model('Products', productSchema);
I was able to add via POST, and this is returned using the GET to /api/products:
[{"_id":"586d9d3b3d618b1d481a395f","name":"Test Product","sku":"lkiuhygs","price":12.99,"__v":0,"updated_at":"2017-01-05T01:11:23.478Z"}]
Error returned in POSTMAN:
{"message":"Cast to ObjectId failed for value "586d95629202a834e871eff9" at path "_id" for model "Products"","name":"CastError","stringValue":""586d95629202a834e871eff9"","kind":"ObjectId","value":"586d95629202a834e871eff9","path":"_id"}
I admit I am just starting out on this, so the issue may be with me!
The text was updated successfully, but these errors were encountered:
Just a guess, but looking at the error above it seems as though there is a problem record in Mongo where _id is quoted (""586...""), maybe that is causing a problem? Try clearing down your data and making sure that that the new record you post isn't quoted in the DB.
@bnurick you can you provide what you sent via POST? I'd have to agree with @rbalmf as the _id looks like it's a string value starting and ending with ".
I am receiving this on all attempts to GET or DELETE by ID. I was trying a very simple implementation to learn how to build simple REST APIs.
I have, what I thought, was a very simple MEAN stack example.
MODEL DEFINITION:
// Dependencies
var restful = require('node-restful');
var mongoose = restful.mongoose;
// Schema
var productSchema = new mongoose.Schema({
name: String,
sku: String,
price: Number,
updated_at: { type: Date, default: Date.now }
});
// Return model
module.exports = restful.model('Products', productSchema);
I was able to add via POST, and this is returned using the GET to /api/products:
[{"_id":"586d9d3b3d618b1d481a395f","name":"Test Product","sku":"lkiuhygs","price":12.99,"__v":0,"updated_at":"2017-01-05T01:11:23.478Z"}]
So, the POST works, GET all works.
Any PUT or GET specific by the ID errors, example GET request below, and the error.
GET request sent in POSTMAN:
http://localhost:3000/api/products/586d9d3b3d618b1d481a395f
Error returned in POSTMAN:
{"message":"Cast to ObjectId failed for value "586d95629202a834e871eff9" at path "_id" for model "Products"","name":"CastError","stringValue":""586d95629202a834e871eff9"","kind":"ObjectId","value":"586d95629202a834e871eff9","path":"_id"}
I admit I am just starting out on this, so the issue may be with me!
The text was updated successfully, but these errors were encountered: