I need to create a new field from a substring (two characters string) of another field in MongoDB. Help me, please.
Example:
field1 field2
abcdef ab
qwerty qw
opuytj op
My code:
db.mycollection.update({}, {$set : {"field2": { $substr: [ {"field1"}, 0, 2 ] } }},
{upsert:false, multi:true})