Results 1 to 2 of 2

Thread: MongDB Delete in Repository

  1. #1
    Join Date
    Jul 2011
    Posts
    2

    Default MongDB Delete in Repository

    Hello all, I'm using the latest version of MongoDB *with* Repositories and trying to do something like "delete by $field". For example:

    A sample bean:

    Code:
    @Document
    public class Foobar implements Serializable {
    
        @Id
       private Long id;
    
       private String name; 
    }
    A sample Repository

    Code:
    @Document
    public interface FoobarRepository extends MongoRepository<Foobar, Long>{
    
        void deleteByName(final String name);
    }
    All methods inherited from MongoRepository work well...but this one that I tried to define in the interface makes Spring Data barf. Essentially, Spring Data's repository generator thinks "delete" is a field in Foobar....when in actuality, its a*verb*.

    I know there is a @Query annotation I can use...but it seems to only support JSON queries...but isn't that only for *searching* and not *deleting*...is there a way I can tell Spring this query should *delete*? Is there a better way to do this?

    thanks in advance,

    /m

  2. #2
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    The query methods currently only support reading data. To delete entities in combination with predicates have a look at the reference documentation about how to add custom implementations for single methods.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •