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 7037589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:33:49+00:00 2026-05-28T01:33:49+00:00

I have MongooseJS schema as follow: var UserSchema = new Schema({ name : String,

  • 0

I have MongooseJS schema as follow:

var UserSchema = new Schema({
    name            : String,
    app_key         : String,
    app_secret      : String,
    tasks           : [{ type   : Schema.ObjectId, 
                            ref : 'Task'}]
})

var ActionSchema = new Schema({
    name            : String,
    description     : String,
    module          : String
})

var enumTaskState = ['New', 'Indexing', 'Idle', 'In Queue', 'Working'];
var TaskSchema = new Schema({
    name            : String,
    lastPerformed   : Date,
    folder          : String,
    actions         : [{type    : Schema.ObjectId, 
                        ref     : 'Task'}],
    user            : { type    : Schema.ObjectId, 
                        ref     : 'User'},
    status          : { type    : String,
                        enum    : enumTaskState,
                        default : 'New'}
})

Problem is, when I set a task’s user, do I manually have to go to the user and add a task there too? This seems like extra work (redundancy), is there an option in mongoosejs that will allow me to specify the relations it will handle everything by itself?
Thanks.

  • 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-05-28T01:33:50+00:00Added an answer on May 28, 2026 at 1:33 am

    MongoDB is not a relational database, it is a document based based database.

    You can get a user’s list of tasks by querying the TaskSchema and looking for the user you want. Just make sure to add an index so it will be a fast query:

    user: {type: Schema.ObjectId, ref: 'User', index: true}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Mongoose schema that embeds another: var EmbedSchema = new Schema({
The following test script says I have 46 records: var mongoose = require('mongoose'), Schema
This is my locationsModel.js file: var LocationSchema, LocationsSchema, ObjectId, Schema, mongoose; mongoose = require('mongoose');
I currently have all my models (Schema definitions) in the /models/models.js file for my
I have a document that looks like: { personName: Some name, metaDetails: { visits:
Does anyone know how to test Mongoose Validations? Example, I have the following Schema
Have a xml string, goal is to replace an xml element value to a
I have the below schema (apologies that it is in coffeescript) Schema = mongoose.Schema
I have nodejs application with mongodb(mongoose). like this: var mongoose = require('mongoose'); var express
I have a problem with embedded document update. My defined Schemas: var Talk =

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.