troubleshooting Question

Why does this query not work?

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
2 Comments1 Solution137 ViewsLast Modified:
Here's my URL:


Here's my route:

router.get('/companies/activities/:activityId', async(req, res)=> {
      try {
            let activityId=req.params.activityId;
        await Activity.getOne(activityId);
    } catch (err) {
        res.send(Proposal.error('An unexpected error was encountered while trying to load your proposal. Please try again.'));

Here's my service:

const { ObjectId } = require('mongodb');
const { Util } = require('node-utils');
const moment = require('moment-timezone');
const Service = require('./service');

const mongoose = require('mongoose');
const ProposalSchema = require('../schemas/ProposalSchema');
const CompanySchema = require('../schemas/CompanySchema');
const UserSchema = require('../schemas/UserSchema');
const ActivitySchema = require('../schemas/ActivitySchema');

class Activity extends Service {

    constructor() {

        this.collection = 'activities';
        this.plural = 'activities';
        this.singular = 'activity';
        this.model = mongoose.model('Activity', ActivitySchema);        
        //this.fields = require('../lib/model-proposal');
	   getOne(activityId) {
        return new Promise((resolve, reject) => {
            let activity_Id = this._getId(activityId);
            this.model.findOne({ _id: activity_Id }, (err, res) => {
                if (err) { console.log(err); reject(err); }

module.exports = new Activity();

Open in new window

The _getId method is in the "service.js" service and that's this guy:

    _getId(id) {
        try {
            if (typeof id == 'object') {// && id instanceof ObjectID) {
                return id;
            } else if (typeof id == 'string') {
                return new ObjectID(id);
            } else {
                return false;
        } catch (err) {
            console.log('Error: ', err);
            return false;

In my collection, I have this:

The table seems to be set, yet I'm getting this error:


So, my "getOne" query is failing, but I don't know why.

Do you see anything that I'm doing wrong? How do I go about troubleshooting this thing?


I've been able to console out my id as well as all of the obvious elements...
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros