Reputation: 57
I'm having a lot of trouble passing in an objectId as my URL parameter. I know that the ObjectId in MongoDB is a hex value, and that I need to do some conversions, but I'm getting errors with every method I use to do this.
Currently, the error that I'm getting states, "Argument passed in must be a single String of 12 bytes or a string of 24 hex characters."
var mongo = require('mongodb').MongoClient;
var ObjectID = require('mongodb').ObjectID;
app.get('/characters/:id', function (req, res) {
console.log(req.params.id);
var collection = db.collection('Character');
_id = new ObjectID(req.params.id);
});
The request I'm passing is:
address/characters/:565dffa7463e4c60b1166f43
Thanks for any help on this.
Upvotes: 2
Views: 4535
Reputation: 65
the request should be: address/characters/565dffa7463e4c60b1166f43
then the req.params.id becomes 565dffa7463e4c60b1166f43.
Upvotes: 1