0

I have a document that looks like this:

{
 "id":1,
 "layers": 
           [{
            "id" : 100,
            "files": [{
                       "id":1,
                       "name":"test"
                     }]
            }]
   }

@Document(collections="tests")
public class Test() {
   string id
   Set<..> layers;
}

public class Layers() {
 List<..> files;
}

Is it possible (given a documentId and and layerId) to add a new file object in one query ? something like

db.test.update(
  { _id: 1 },
  { $push:
     {
       "layers.100.files": {"id":2,"name":"test2:}
     }
  }
)

when I try the above I get an error like: cannot use the part (contentLayers ....) to traverse the element ....

1 Answer 1

2
db.test.update(
  { $and: [{_id: "1"}, {"layers.id": "100" }]},
  { $push:
     {
       "layers.$.files": 1
     }
  }
)

Here is the version non-java, the important point is having this $ before the array

Note there 'might' be an other way of doing this but the above works for me

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.