I seem to have run into a roadblock while using MongoDB, and would like to know if there is anyway around it without having to modify my database structure. Right now my database structure is as follows:
Company=
{
_id:1,
properties:[
{
property_id: 1
tags : [
{
tag_id: 1
tag_value: 1000
channels: [
{
channel_id:1
channel_name:"test1"
},
{
channel_id:2
channel_name:"test2"
}]
},
{
tag_id:2
tag_value: 2500
channels: [
{
channel_id:2
channel_name:"test2"
},
{
channel_id:3
channel_name:"test3"
}]
}]
},
{
property_id: 2
tags : [
{
tag_id: 3
tag_value: 500
channels: [
{
channel_id:1
channel_name:"test1"
},
{
channel_id:3
channel_name:"test3"
}]
},
{
tag_id: 4
tag_value: 5000
channels: [
{
channel_id:1
channel_name:"test1"
}]
}]
}]
}
I am running into a problem where I cannot figure out a way to update specific tag_ids in a property. For example, I want to change the value of tag_id 4 in property 2 to 100. Or I want to add a channel to the channel array in tag_id 3.
What I would like to do would be something similar to this:
db.company.update({_id:1, "properties.property_id":2, "tags.tag_id":4}, {"properties.$.tags.$.tag_value":100});
However I know this isn't supported in the current version of MongoDB, and it is already in JIRA. So my question is, is there anyway to update a value of a document where you need to specify two different conditions in order to access it. I know that I could do properties.1.tags.0, however I will not know the order of my arrays, and my queries will be run programatically.
Any help would be great, even a conformation that I must restructure my table.
Thank you