I'm trying to update the value of a field in a MongoDB collection by concatenating it with a literal string. Besides this, the field is an integer, and I want to add a "0" in front, so it will became a string.
I've read that I can't use the old value of the field in a single update instruction, so I'm using a forEach() method.
Here is the code:
db.col_1.find({"field_1": {$lt: 10000}}).forEach( function(i){
db.col_1.update({_id: i._id},
{$set: { "field_1": {$concat: ["0", i.field_1]}}}
)
});
The return result is :
The dollar ($) prefixed field '$concat' in 'field_1.$concat' is not valid for storage.
I'm sure I'm not writting the $concat command properly, is there any way to do this?
{$set: { "field_1": "0" + i.field_1 } }
– Tourbillion