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

  • Home
  • SEARCH
  • 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 1091255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:29:50+00:00 2026-05-16T23:29:50+00:00

Note: I ended up answering my own question shortly after posting this. Thanks and

  • 0

Note: I ended up answering my own question shortly after posting this. Thanks and sorry if you spent time reading my rediculously long post.

Introduction

I’m sort of a Mongo noob, just trying to get the hang of things here.

I am looking at trying to create a hierarchical data structure to which i can add nodes/leaves dynamically. The schema is fixed, but the nodes on any given tree should be able to change at any time. The main thing I’m looking for is how to add/remove nodes on deeply nested nodes without rewriting the whole tree.

Here’es an example for a static analysis program, the collection is called “builds”. A sparse document would look like this (_id’s removed for brevity’s sake):

{ name: "build from changeset #5678", 
  assemblies: [
    { name: "someAssembly1.dll",
      warnings: [
        { level: 0,
          message: "something doesn't conform to our standard"
        }
      ] 
    }             
  ]
}

So to kick it off, I do the following;

db.builds.insert({name: "build from changeset #5678})

Then, add an assembly:

db.builds.update({name: "build from changeset #5678"},
                 {$addToSet: {assemblies: {name: "someAssembly1.dll"}}})

The REAL Question

Now, how do I add a warning?
I was thinking it might be something like this:

db.builds.update({
  name: "build from changeset #5678",
  "assemblies.name": "someAssembly1.dll"
},{
 $addToSet: {
   assemblies.warnings: {
     level: 0,
     name: "something doesn't conform to our standard"
   }
 }
})

But that gives me “missing : after property id (shell):0”

I also tried putting quotes around “assemblies.warnings”, but that says “can’t append to array using string field name [warnings]”

Does anyone know Mongo any better than I and can help me?

Am I wrong in trying to do deeply nested trees on Mongo? Would I be better off doing it with multiple collections and somewhat relational?

I was under the impression that NOT doing relational (as well as ACID) was one of the main benefits for Mongo, but then again, maybe thats just my noob showing again.

  • 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-16T23:29:50+00:00Added an answer on May 16, 2026 at 11:29 pm

    So I’ve been struggling with this all day, and sure enough, the moment I post it to StackOverflow I run across something that gives me the answer. The proper answer looks like this:

    db.builds.update({
      name: "build from changeset #5678",
      "assemblies.name": "someAssembly1.dll"
    },{
     $addToSet: {
       "assemblies.$.warnings": {
         level: 0,
         name: "something doesn't conform to our standard"
       }
     }
    })
    

    Note the

    "assemblies.$.warnings"
    

    I found it here: http://groups.google.com/group/mongodb-user/browse_thread/thread/e8f4ea5dc1955a98#

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

Sidebar

Related Questions

Note: I realize that this is probably an open-ended question, so go ahead and
On the IOC Castle Windsor wiki [Editor's Note: After this question was written, the
Note, this is not a duplicate of .prop() vs .attr() ; that question refers
(Note: This is not a question about what is the best way with code
NOTE: This is a followup to my question here. I have a program that
NOTE: This is an old question and the answers here no longer works (since
NOTE: I have ended up reporting this as a bug to the android project
note: i only want to move 1 shape at a time Circle.prototype.create = function(){
Note: Not sure if this is the right stack, please tell if I should
Note: I had another similar question about how to GZIP data using Ruby's zlib

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.