2

I am new to Spring-data, so pardon me if my question is to naive

I am trying to query the document which looks like this:

     {
       _id: 1,
       name: "sue",
       age: 19,
       type: 1,
       status: "P",
       favorites: { artist: "Picasso", food: "pizza" },
       finished: [ 17, 3 ],
       badges: [ "blue", "black" ],
       points: [
          { points: 85, bonus: 20 },
          { points: 85, bonus: 10 }
       ]
     }

I wanted to do the query which gives me the list of the entries which contains the favourites.artist="Picasso".

I know how to do this using the MongoTemplate I wanted to do that using MongoRepository.

I was reading some document which shows query like this

findByFavorites(Favorites favorites)

but I couldn't find anything with which I can query using the field of the embedded document.

1 Answer 1

1

It should be

    findByFavoritesArtist(@Param("favorites.artist") String artist);

So you just concatenate together the names of the properties in the property path in our embedded object. It is possible that the above query is redundant and you can leave out the @Param annotation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.