Insert array from another parrent document?

I have a todo app where I have sub categories

I have a category collection with a document field called: categoryArray

when you are in a sub category there are a _id in the url: BadeRS2NFWND8p9tz

howto select the document with the _id in the url and get the field: categoryArray from it and insert it in a new document?

Categories.update({
    _id: newDocId
    }, 
    {
      $push: {
        categoryArray: parrentCategoryArray???
      },
    });

Still need a little help with it :slight_smile:

It wasn’t clear what you need, but you may want to take a look at this resources:

https://docs.mongodb.com/manual/reference/operator/update/positional/
https://docs.mongodb.com/manual/reference/operator/projection/positional/

it worked with.


 // insert the categoryArray from this URL and insert with the new cat id
    Categories.find({_id: thisurl_catId1}).forEach(function(doc){
        Categories.update(
            { _id: newDocId },
            { $push: { categoryArray: { $each: doc.categoryArray } } }
            
        )
        console.log("push each ");  
    });

dont know if i need to use forEach, but it looks like it works