Cast to ObjectId failed for value on findById [closed]What's Mongoose error Cast to ObjectId failed for value XXX at path “_id”?Find document with array that contains a specific valueHow to resolve Mongoose Connect UNKNOWN?Why this error coming while running nodejs server?Angular client-side image upload into JSON document and saved to mongo through node/expressPUT/ update operation fails in $resource AngularJS client in rest based app (mongoose insert / update issue).“Cannot GET /db/read/getall” accessing node.js express API using reverse proxy nginx on digitalocean dropletMongoose pre.remove middleware of objects in array are never calledWhy express.Router() while separating routesHow to send github OAuth data to client?
On studying Computer Science vs. Software Engineering to become a proficient coder
What does this quote in Small Gods refer to?
How can a Lich look like a human without magic?
Is a diamond sword feasible?
Was the Highlands Ranch shooting the 115th mass shooting in the US in 2019
How are Core iX names like Core i5, i7 related to Haswell, Ivy Bridge?
How are one-time password generators like Google Authenticator different from having two passwords?
What did Rocket give Hawkeye in "Avengers: Endgame"?
Does Lawful Interception of 4G / the proposed 5G provide a back door for hackers as well?
How can I answer high-school writing prompts without sounding weird and fake?
LocalDate.plus Incorrect Answer
"Fīliolō me auctum scito, salva Terentia"; what is "me" role in this phrase?
Why does a C.D.F need to be right-continuous?
51% attack - apparently very easy? refering to CZ's "rollback btc chain" - How to make sure such corruptible scenario can never happen so easily?
Is there a faster way to calculate Abs[z]^2 numerically?
What are some possible reasons that a father's name is missing from a birth certificate - England?
Why can't RGB or bicolour LEDs produce a decent yellow?
What is the significance of 4200 BCE in context of farming replacing foraging in Europe?
What is the best way for a skeleton to impersonate human without using magic?
On what legal basis did the UK remove the 'European Union' from its passport?
We are two immediate neighbors who forged our own powers to form concatenated relationship. Who are we?
How to pronounce "r" after a "g"?
Is it a Munchausen Number?
How to make the table in the figure in LaTeX?
Cast to ObjectId failed for value on findById [closed]
What's Mongoose error Cast to ObjectId failed for value XXX at path “_id”?Find document with array that contains a specific valueHow to resolve Mongoose Connect UNKNOWN?Why this error coming while running nodejs server?Angular client-side image upload into JSON document and saved to mongo through node/expressPUT/ update operation fails in $resource AngularJS client in rest based app (mongoose insert / update issue).“Cannot GET /db/read/getall” accessing node.js express API using reverse proxy nginx on digitalocean dropletMongoose pre.remove middleware of objects in array are never calledWhy express.Router() while separating routesHow to send github OAuth data to client?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to get a single item from Mongodb, Mongoose with the code below. In Postman make a get request with an Id to
http://localhost:5000/api/report/l5c959036c3dfe2338412be8e and the error returned is
"message": "Cast to ObjectId failed for value
"l5c959036c3dfe2338412be8e" at path "_id" for model "Report
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const cors = require("cors");
const bodyParser = require("body-parser");
mongoose.connect(
"mongodb://localhost:27017/reports",
useNewUrlParser: true, useCreateIndex: true
);
mongoose.connection.on(
"error",
console.error.bind(console, "connection error:")
);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded( extended: true ));
app.use(cors());
app.get("/api/report/:id", (req, res) =>
Report.findById(req.params.id, (err, report) =>
if (err) return res.status(404).send( message: err.message );
return res.send( report );
);
);
thanks for any help!
node.js mongodb mongoose
closed as off-topic by Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao♦ Mar 23 at 12:03
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao
add a comment |
I am trying to get a single item from Mongodb, Mongoose with the code below. In Postman make a get request with an Id to
http://localhost:5000/api/report/l5c959036c3dfe2338412be8e and the error returned is
"message": "Cast to ObjectId failed for value
"l5c959036c3dfe2338412be8e" at path "_id" for model "Report
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const cors = require("cors");
const bodyParser = require("body-parser");
mongoose.connect(
"mongodb://localhost:27017/reports",
useNewUrlParser: true, useCreateIndex: true
);
mongoose.connection.on(
"error",
console.error.bind(console, "connection error:")
);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded( extended: true ));
app.use(cors());
app.get("/api/report/:id", (req, res) =>
Report.findById(req.params.id, (err, report) =>
if (err) return res.status(404).send( message: err.message );
return res.send( report );
);
);
thanks for any help!
node.js mongodb mongoose
closed as off-topic by Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao♦ Mar 23 at 12:03
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao
l5c959036c3dfe2338412be8e
is not a valid objectId. Remove thel
from the begning of the id.
– Anthony Winzlet
Mar 23 at 10:51
Means what it says.l5c959036c3dfe2338412be8e
is not valid for anObjectId
value.5c959036c3dfe2338412be8e
without the "l" on the beginning is however valid. I suggest a typo.
– Neil Lunn
Mar 23 at 10:52
add a comment |
I am trying to get a single item from Mongodb, Mongoose with the code below. In Postman make a get request with an Id to
http://localhost:5000/api/report/l5c959036c3dfe2338412be8e and the error returned is
"message": "Cast to ObjectId failed for value
"l5c959036c3dfe2338412be8e" at path "_id" for model "Report
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const cors = require("cors");
const bodyParser = require("body-parser");
mongoose.connect(
"mongodb://localhost:27017/reports",
useNewUrlParser: true, useCreateIndex: true
);
mongoose.connection.on(
"error",
console.error.bind(console, "connection error:")
);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded( extended: true ));
app.use(cors());
app.get("/api/report/:id", (req, res) =>
Report.findById(req.params.id, (err, report) =>
if (err) return res.status(404).send( message: err.message );
return res.send( report );
);
);
thanks for any help!
node.js mongodb mongoose
I am trying to get a single item from Mongodb, Mongoose with the code below. In Postman make a get request with an Id to
http://localhost:5000/api/report/l5c959036c3dfe2338412be8e and the error returned is
"message": "Cast to ObjectId failed for value
"l5c959036c3dfe2338412be8e" at path "_id" for model "Report
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const cors = require("cors");
const bodyParser = require("body-parser");
mongoose.connect(
"mongodb://localhost:27017/reports",
useNewUrlParser: true, useCreateIndex: true
);
mongoose.connection.on(
"error",
console.error.bind(console, "connection error:")
);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded( extended: true ));
app.use(cors());
app.get("/api/report/:id", (req, res) =>
Report.findById(req.params.id, (err, report) =>
if (err) return res.status(404).send( message: err.message );
return res.send( report );
);
);
thanks for any help!
node.js mongodb mongoose
node.js mongodb mongoose
asked Mar 23 at 10:44
GosmithGosmith
606
606
closed as off-topic by Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao♦ Mar 23 at 12:03
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao
closed as off-topic by Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao♦ Mar 23 at 12:03
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Neil Lunn, Anthony Winzlet, chridam, Bhargav Rao
l5c959036c3dfe2338412be8e
is not a valid objectId. Remove thel
from the begning of the id.
– Anthony Winzlet
Mar 23 at 10:51
Means what it says.l5c959036c3dfe2338412be8e
is not valid for anObjectId
value.5c959036c3dfe2338412be8e
without the "l" on the beginning is however valid. I suggest a typo.
– Neil Lunn
Mar 23 at 10:52
add a comment |
l5c959036c3dfe2338412be8e
is not a valid objectId. Remove thel
from the begning of the id.
– Anthony Winzlet
Mar 23 at 10:51
Means what it says.l5c959036c3dfe2338412be8e
is not valid for anObjectId
value.5c959036c3dfe2338412be8e
without the "l" on the beginning is however valid. I suggest a typo.
– Neil Lunn
Mar 23 at 10:52
l5c959036c3dfe2338412be8e
is not a valid objectId. Remove the l
from the begning of the id.– Anthony Winzlet
Mar 23 at 10:51
l5c959036c3dfe2338412be8e
is not a valid objectId. Remove the l
from the begning of the id.– Anthony Winzlet
Mar 23 at 10:51
Means what it says.
l5c959036c3dfe2338412be8e
is not valid for an ObjectId
value. 5c959036c3dfe2338412be8e
without the "l" on the beginning is however valid. I suggest a typo.– Neil Lunn
Mar 23 at 10:52
Means what it says.
l5c959036c3dfe2338412be8e
is not valid for an ObjectId
value. 5c959036c3dfe2338412be8e
without the "l" on the beginning is however valid. I suggest a typo.– Neil Lunn
Mar 23 at 10:52
add a comment |
1 Answer
1
active
oldest
votes
Try removing the "I" from the objectId you pass as the param, as suggested in the comments.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try removing the "I" from the objectId you pass as the param, as suggested in the comments.
add a comment |
Try removing the "I" from the objectId you pass as the param, as suggested in the comments.
add a comment |
Try removing the "I" from the objectId you pass as the param, as suggested in the comments.
Try removing the "I" from the objectId you pass as the param, as suggested in the comments.
answered Mar 23 at 11:46
Moad EnnagiMoad Ennagi
47048
47048
add a comment |
add a comment |
l5c959036c3dfe2338412be8e
is not a valid objectId. Remove thel
from the begning of the id.– Anthony Winzlet
Mar 23 at 10:51
Means what it says.
l5c959036c3dfe2338412be8e
is not valid for anObjectId
value.5c959036c3dfe2338412be8e
without the "l" on the beginning is however valid. I suggest a typo.– Neil Lunn
Mar 23 at 10:52