Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

convert string or string array to object mongoose object id

function toObjectId(ids) {

    if (ids.constructor === Array) {
        return ids.map(mongoose.Types.ObjectId);
    }

    return mongoose.Types.ObjectId(ids);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #convert #string #string #array #object #mongoose #object #id
ADD COMMENT
Topic
Name
3+2 =