title: Async await usage for MongoDB repository
body: <p>I have a MongoDB repository class as you see below: </p>
  
  <pre><code>public class MongoDbRepository&lt;TEntity&gt; : IRepository&lt;TEntity&gt; where TEntity : EntityBase
  {
      private IMongoClient client;
      private IMongoDatabase database;
      private IMongoCollection&lt;TEntity&gt; collection;
  
      public MongoDbRepository()
      {
          client = new MongoClient();
          database = client.GetDatabase("Test");
          collection = database.GetCollection&lt;TEntity&gt;(typeof(TEntity).Name);
      }
  
      public async Task Insert(TEntity entity)
      {
          if (entity.Id == null)
          {
              entity.Id = Guid.NewGuid();    
          }
          await collection.InsertOneAsync(entity);
      }
  
      public async Task Update(TEntity entity)
      {
          await collection.FindOneAndReplaceAsync(x =&gt; x.Id == entity.Id, entity, null);
      }
  
      public async Task Delete(TEntity entity)
      {
          await collection.DeleteOneAsync(x =&gt; x.Id == entity.Id);
      }
  
      public IList&lt;TEntity&gt; SearchFor(Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate)
      {
          return collection.Find(predicate, null).ToListAsync&lt;TEntity&gt;().Result;
      }
  
      public IList&lt;TEntity&gt; GetAll()
      {
          return collection.Find(new BsonDocument(), null).ToListAsync&lt;TEntity&gt;().Result;
      }
  
      public TEntity GetById(Guid id)
      {
          return collection.Find(x =&gt; x.Id == id, null).ToListAsync&lt;TEntity&gt;().Result.FirstOrDefault();
      }
  }
  </code></pre>
  
  <p>And I use this class as in the following code piece:</p>
  
  <pre><code>    public void Add()
      {
          if (!string.IsNullOrEmpty(word))
          {
              BlackListItem blackListItem =
                  new BlackListItem()
                  {
                      Word = word,
                      CreatedAt = DateTime.Now
                  };
  
              var blackListItemRepository = new MongoDbRepository&lt;BlackListItem&gt;();
              blackListItemRepository.Insert(blackListItem);
              Word = string.Empty;
              GetBlackListItems();
          }
      }
  </code></pre>
  
  <p>It works fine but I get the following warning for the line <code>blackListItemRepository.Insert(blackListItem);</code></p>
  
  <blockquote>
    <p>Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.</p>
  </blockquote>
  
  <p>I'm new to await and async keywords and I'm not sure if I'm using them correctly. Do you have any suggestions for my repo class and my usage?</p>
  
  <p>Thanks in advance,</p>