1

I have a hierarchical data structure presenting answers for each question for each exam for each teacher stored in MongoDB like below:

db.foo.insert({name:"teacher1"}); //Done

db.foo.update({name:"teacher1"},{$push:{"exams":{name:"exam1"}}}); //Done

db.foo.update({"exams.name":"exam1"},{$push:{"exams.$.questions":{name:"question1"}}}); //Done

db.foo.update({"exams.questions.name":"question1"},
    {$push:{"exams.$.questions.$.answers":{name:"answer1"}}}); 

// Error => can't append to array using string field name [$]

I appreciate your comments,

0

1 Answer 1

2

You can't use two positional operators. As per :http://www.mongodb.org/display/DOCS/Updating :

The $ operator (by itself) means "position of the matched array item in the query". Use this to find an array member and then manipulate it.

Currently the $ operator only applies to the first matched item in the query.

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.