I have a MongoDB collection with some documents that have a field called Personal.FirstName and another field call Personal.Surname. Some documents are messed up and have the persons first name and last name in both fields. For example there are some documents that have Personal.FirstName = 'John Doe' and Personal.Surname = 'John Doe'.
I want to write a mongo update statement that will do the following:
- Find all of the documents that have a Personal section
- Find all of the documents where Personal.FirstName == Personal.Surname
- Update Personal.FirstName to be just the first part of Personal.FirstName before the space
- Update Personal.Surname to be just the second part of Personal.Surname after the space
Is this possible in a mongo update statement? I am new to mongo and know very little about how to query it.
EDIT: here is an example document
{
"_id" : LUUID("fcd140b1-ec0f-0c49-aa79-fed00899290e"),
"Personal" : {
"FirstName" : "John Doe",
"Surname" : "John Doe"
}
}