Get only value of field

How i can get only value of nested field (“test.test1.nestedField”). When i try to get it with projection (“test.test1.nestedField”) i receive: {“test”: {“test1”: {“nestedField”:“value”} } }

Hi @Igor_01710

In MongoDB you will get the value of the nested field and the structure of the document returned hence {“test”: {“test1”: {“nestedField”:“value”} } }. If you need to work with that field, you could create a class to represent the data (creating a POJO/Plain Old Java Objects). You can find several examples of the classes for mflix in “mflix-java/src/main/java/mflix/api/models”. If you just need that field, when the projection returns you could convert to Json (toJson()) and extract the field from the Json. You can find more examples in the example with the MongoDB Java Driver source on Github.

Hope this helps!

Thank you! I have to work with all structure.

1 Like