I have documents in the following format:
{
_id: "1232014",
account: "123",
year: 2014,
country: 826
}
The _id field is made up of the account field and the year field combined.
However, I've since found that the same account in the same year can have data in different countries, and I'm getting a duplicate key error.
What I need to do is have the country field as part of the _id field too e.g.
_id: "1232014826"
Since I'm using a value from within the document as part of the update, I don't think I can use $set, so I've tried to use save() within a forEach() query instead:
db.account_data.find({"_id" : "1232014"}).forEach(function(doc) {
doc._id = doc._id + doc.country;
db.collection.save(doc);
});
This isn't working.
Is there any way to update _id? Or is this impossible because it is primary key field?