express - OData - Strange index with MongoDB [Mongoose: Cast Error] -


i have mongodb documents schema:

id: {type: "id", key: true, computed: true, nullable: false}, name: {type: "string", nullable: false, maxlength: 50} 

and these documents exposed odata small web application (i'm using express, jaydata, , mongoose). these of documents:

{ "_id" : objectid("5343fd656b9c5c084b8f2a70"), "name" : "service74"}, { "_id" : objectid("5343fd656b9c5c084b8f2a6f"), "name" : "service73"}, { "_id" : objectid("5343fd656b9c5c084b8f2a6e"), "name" : "service72"}, ... 

if type address http://localhost:8080/marketplace/services('5343fd656b9c5c084b8f2a70') correspond service74 result:

... <d:id>ntm0m2zknju2yjljnwmwodriogyyytcw</d:id> <d:name>service74</d:name> ... 

of course if use id specified in result obtain same page.

the problem occurs when try use mongoose function findbyid:

app.post("/addcompare/:id", function(req, res) {     console.log(req.params.id);     services.findbyid(req.params.id, function(err, service) {         if(!err) {console.log(service);}         else {console.log(err);}     });     res.send(200); }); 

i ntm0m2zknju2yjljnwmwodriogyyytcw , error:

{ message: 'cast objectid failed value "ntm0m2zknju2yjljnwmwodriogyyytu5" @ path "_id"',   name: 'casterror',   type: 'objectid',   value: 'ntm0m2zknju2yjljnwmwodriogyyytu5',   path: '_id' } 

where wrong? tell me if miss other information...

thanks.

ps: found similar problem here mongoose: cast objectid failed, if change model definition mongoose (in don't declare id) including definition:

var serviceschema = mongoose.schema({     _id: string,     ... 

nothing changes...

the 5343fd656b9c5c084b8f2a70 internal identifier of entity used on server-side. value base64-encoded on odata, why receive ntm0m2zknju2yjljnwmwodriogyyytcw in id field. entity can retrieved id calling atob(req.params.id) on received id.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -