4
{
"_id" : "55dcb404478e7227203d3a65",
"Nome" : "Grupo Familia",
"Pessoas" : [
{
"PessoaId" : "55dcb425478e72207833e970",
"Nome" : "Carlos",
"Habilidades" : [
{
"HabilidadeId" : "55dcb433478e7229b0e3ee07",
"Nome": "Pular",
"Macetes": [
{"Descricao" : "Usar um tênis macio"},
{"Descricao" : "Se alongar"}
]
},
{
"HabilidadeId" : "55dcb425478e72207833e961",
"Nome" : "Correr"
}
],
}
],
}
I have this Collection on Mongodb and I have the following question: How do I add a new skill trick "correr"
?
Answer my question, but in my real case, I do not know what index the person has and nor the skill index, can be the top person of Collection and the twentieth skill, How would you insert a headline in this case ? ( without entering the Dice number directly)
– Gustavo Gois Cardoso
Do you know Person and Ability? If you know, use them in the query instead of "_id". When manipulating the array, you could use $push. Has several operations specific to handle array, check here: http://docs.mongodb.org/manual/reference/operator/update-array/
– Vitor De Mario
What is the syntax for using these id’s? Suppose Personal = "teste1" and Ability = "teste2", as I would do this query ?
– Gustavo Gois Cardoso
It would be like that:
db.bla.update({"Pessoas.Habilidades.HabilidadeId" : "55dcb425478e72207833e961"}
, looking directly for theHabilidadeId
.– Vitor De Mario
I did that too and in $set I used this : "$set": { "People.$.Habilitys.$. Tricks": [ { "Ability": "new", "Name": "Skip" } ] } However it does not work
– Gustavo Gois Cardoso
This question may also help: https://stackoverflow.com/questions/23821392/how-to-update-valuof-a-key-in-a-list-of-a-json-in-mongo
– Vitor De Mario
That way I could get up to skills, but not up to tricks ..
– Gustavo Gois Cardoso
Discussion is getting too long, let’s take pro chat: https://chat.stackexchange.com/rooms/11910/stackoverflow
– Vitor De Mario