title: spring data MongoRepository check if a document exists before inserting by querying with entire document
body: <p>I am trying to create a webservice which receives a json object and performs some action based on whether the object already exists as a document in my mongodb or not. If the document already exists, I have to just perform my action. If it doesn't i have to insert it first and then perform the action.</p>
  
  <p>Using spring data MongoRepository or MongoTemplate, how do I check if a document already exists - using the entire document I am about to insert?
  I cannot use _id here. If the entire document already exists, I don't have to insert a new document. But if at least one field is different, I have to enter a new document.</p>
  
  <p>Eg:</p>
  
  <pre><code>@Document (collection = "foo")
  class Foo {
  
     @Id
     String id;
     String name;
     List&lt;Address&gt; address   
     ... many more attributes
  }
  </code></pre>
  
  <p>If I get a request using an object of Foo without _id, how do I check if this already exists as a document in my mongodb collection?</p>
  
  <p>Thanks!</p>