I need to assign consecutively increasing nameset identifiers. It depends on the:
A field that contains the following identifier to be generated: curId
A set mysetcontaining a name / value pair, where value is an identifier and name is a name
Problem:
I need to atomize:
1. Make sure it mysetcontains a name. If not,
2. Generate a new identifier using $ inc.
3. Insert the name / id pair into myset.
I can’t find a way to do this in mongodb, at least without introducing race conditions. Suggestions are welcome.
Refresh
Example document (how it should look).
Before adding 'c':
{
"mySet": [
{
"name": 'a',
"value" : 1
},
{
"name": 'b',
"value" : 2
}
]
}
'c'. 3, , 'c'.
{
"mySet": [
{
"name": 'a',
"value" : 1
},
{
"name": 'b',
"value" : 2
},
{
"name": 'c',
"value" : 3
}
]
}
'c' .
, "c" . "3", id "c".