Advice

I have never queried mongoDB before using C#, usually only things like SQL Server which seem more straight forward to me. I am also not an expert in C#, so please do not beat me up. Trying to learn.

I have a collection called notification which has:

  • _id: string (a custom id value, not system generated)

  • _class: string

  • _content: string

and in C# I am trying to search for a specific record by the unique _id and just return true or false from a function.

It runs, however, it hits the count and bails out of the function and I can't tell what it is doing.

using MongoDB.Bson.Serialization.Attributes;
using System;
namespace DataMover
{
 public class Notification
 {
 [BsonId]
 public string Id { get; set; }
 public string _class { get; set; }
 public string content { get; set; }
 }
}
using MongoDB.Driver;
using System.Threading.Tasks;
private async Task<bool> LookupNotification(string id)
{
   MongoClient client = new MongoClient("mongodb://server:27017");
   IMongoCollection<Notification> notificationContent = client.GetDatabase("notifications").GetCollection<Notification>("notification_contents");
   var filter = Builders<Notification>.Filter.Eq(doc => doc.Id, id);
   var count = notificationContent.CountDocuments(filter);
   MessageBox.Show(count.ToString());
   return true;
}