Alsemany
Alsemany

Reputation: 445

MongoSkin don't work with req.params.id

I have this strange issue using mongskin for example

db.collection('collection_name')
.find({integer_id:req.params.id})
.ToArray(function(err,result){
console.log(result);
});

however the result will be empty array [ ] I tried to console.log(req.params.id) and the result is the integer number for example 1

if I use the number directly like

db.collection('collection_name')
.find({integer_id:1})
.ToArray(function(err,result){
console.log(result);
});

in this case the result will be fetched successfully


I don't know what is the issue exactly, is this is a character encoding issue? or something like that?

and please if there's any way to make sure that the req.params.id will work correctly with the database if there's any encoding issue

thank you in advanced

Upvotes: 0

Views: 56

Answers (1)

robertklep
robertklep

Reputation: 203359

integer_id suggests that the id should be a Number, and not a String, which is what req.params.id will be.

So try this:

.find({ integer_id : Number(req.params.id) })

Upvotes: 1

Related Questions