I asked on a previous question on how to find entries in a embedded MongoDB document. Sitting with a new issue now. My structure looks like :
{
"_id" : ObjectId("5260c4bd95f8e3ad08000000"),
"ip" : "127.0.0.1",
"services" : [
{
"port" : "22"
}
]}
I want to add a new key/value pair to services.port where the port is 22, so that it looks like this :
{
"_id" : ObjectId("5260c4bd95f8e3ad08000000"),
"ip" : "127.0.0.1",
"services" : [
{
"port" : "22",
"product" : "ssh"
}
]}
This is the update I run :
db.hosts.update({ "ip" : "127.0.0.1" }, { $addToSet : { services : { "port" : "22", "product" : "ssh" }}});
And this is what I am getting
{
"_id" : ObjectId("5260c4bd95f8e3ad08000000"),
"ip" : "127.0.0.1",
"services" : [
{
"port" : "22"
},
{
"port" : "22",
"product" : "ssh"
}
]}
Anyone know what I am doing wrong? Should I delete the entry and recreate it?