Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8599909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:30:00+00:00 2026-06-12T01:30:00+00:00

I have this Mongoose Schema. var mongoose = require(‘mongoose’) , dev = require(‘../db’).dev(); var

  • 0

I have this Mongoose Schema.

var mongoose = require('mongoose')
  , dev      = require('../db').dev();

var schema = new mongoose.Schema({
  date: {
    type: Date,
    default: Date.now()
  },
  company: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Company'
  },
  questionnaire: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Questionnaire'
  }
});

module.exports = dev.model('Survey', schema);

I want to find only the surveys which have a specific company id. How do I do that? I tried (with my Express handler):

app.get('/survey', function(req, res) {
  Survey.find({ company: req.query.company })
        .populate('questionnaire')
        .exec(function(err, surveys) {
                return res.json(surveys);
        });
      });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:30:01+00:00Added an answer on June 12, 2026 at 1:30 am

    In your latest comment you say that the company field of the Surveys collection is actually a string and not and ObjectId and that’s why this isn’t working. Because your schema definition declares company as an ObjectId, Mongoose will cast your req.query.company value to an ObjectId and then query for documents in Surveys where their company property is an ObjectId with the same value. So if company is a string in the database it won’t match.

    If you update the company values in Surveys to be ObjectIds instead of strings then this will work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this model: var HuntGroupSchema = new Schema({ name : { type: String,
I have a model called Application: var ApplicationSchema = new mongoose.Schema({ name : {type:
i have mongoose schema named administrator var administratorSchema = new mongoose.Schema({ username : String,
I have the following Mongoose schema that embeds another: var EmbedSchema = new Schema({
Let's suppose I have a Word model with this schema var Word = new
I have a schema like this (simplified) var Language = new Schema({ name: String
I have nodejs application with mongodb(mongoose). like this: var mongoose = require('mongoose'); var express
This is my locationsModel.js file: var LocationSchema, LocationsSchema, ObjectId, Schema, mongoose; mongoose = require('mongoose');
I have a Mongoose schema (excerpt below): var PersonSchema = new Schema({ name :
If I have a schema like this: var Word = new Schema({ name: {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.