Answer the question
In order to leave comments, you need to log in
How to compare variable with ObjectId (mongoose)?
I get an ID, but I don't know how to compare if it's correct.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
var id = req.params.id;
if (id instanceof ObjectId) {
console.log('yes');
} else {
console.log('no');
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question