{
"_id" : ObjectId("59786a62a96166007d7e364dsadasfafsdfsdgdfgfd"),
"someotherdata" : {
"place1" : "lwekjfrhweriufesdfwergfwr",
"place2" : "sgfertgryrctshyctrhysdthc ",
"place3" : "sdfsdgfrdgfvk",
"place4" : "asdfkjaseeeeeeeeeeeeeeeeefjnhwklegvds."
}
}
I have a vast array of similar records in my collection. My task is to sift through all the someotherdata entries and perform the following actions:
- Verify if specific fields are present (for example, place1 might be available in certain records while place4 may not)
- Determine the longest string record among them
The desired output should display the character count for the lengthiest entry as shown below:
{
place1: 123,
place2: 12,
place3: 17
place4: 445
}
Given that I am utilizing Mongodb version 3.2.9, which lacks the latest aggregate functions, my approach involves leveraging the Mongodb shell.
EDIT: To clarify further, the goal is to identify the longest record across all documents in the collection. Even though there could be thousands of documents, the result should showcase the longest string length for each field throughout the entire collection.