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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:47:23+00:00 2026-06-18T09:47:23+00:00

I have a multi level schema and I’m trying to add an element to

  • 0

I have a multi level schema and I’m trying to add an element to a list in a deep level using the $ operator.

My schema looks like this and I’m trying to add an object to a specific cList:

var cSchema = mongoose.Schema({c:String,
    cList[
       {
         d1:String
         d2:String   
       }
    ]
});

var bSchema = mongoose.Schema({c:String,
    b:String,
    bList:[cSchema]
});


var aSchema = mongoose.Schema({
    a:String,
    aList:[bSchema]
}); 

I tried to run the following, but count always returns 0:

Model.update( {_id:req.aid, "aList._id":req.params.bid, "bList.$.cList._id":req.params.cid}, 
              {'$addToSet' : {'aList.$.bList.$.cList': req.body}}, 
              function(err,count){

              }
);
  • 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-18T09:47:25+00:00Added an answer on June 18, 2026 at 9:47 am

    The $ operator is for use in the update operator object (2nd argument to update), not the query selector (1st argument). In the query selector, you should be able to use aList.bList.cList._id, and this would let aList.$.bList.$.cList correspond to the first matching element of the embedded cList in the update operator.

    Edit:

    Nested positional ($) operator matching is not supported currently. This ticket shows demand for exactly this feature from a long time ago (2010!), but apparently lower-level code within mongoDB did not make this possible. It seems 10gen is hopeful to get this feature in the 2.6 release.

    It looks like you will have to separately query and update to achieve this with your current schema, or perhaps change your schema to be more flat.

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

Sidebar

Related Questions

Consider we have a multi-level html list that looks like this: <ul class=catalog> <li>
I have a multi-level nav styled as an unordered list that looks like this:
On SQL Server 2005, I have a complex multi-level allocation process which looks like
I have standard multi-level menu like this one: <ul id=nav> <li><a href=#>Home</a></li> <li><a href=#>Dropdown</a>
I have a multi-level lists like this: <ul> <li>Item 1 <ul> <li>Item 1's 1st
I have a graph of multi-level dependecies like this, and I need to detect
Is it possible to have a multi level dropdown menu by using the elements
How can I do a multi-level parent-child sort using Linq if I have a
I have a problem with the generated multi-level menu. I would like each menu
I have a multi-level dropdown menu on my MVC Application and I'm trying to

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.