Kavya Durgam

Kavya Durgam

  • 2k
  • 26
  • 21.8k

Fetching the document from mongodb by passing the parameters

Dec 11 2017 2:51 AM
I need to check the document exixts in the mongodb based on  combination of 3 parameters.
this is the query worked on mongo db command prompt: 
db.FrequencyQuestionForm.find({"data.formList.Identificatio
nDetails.Study_Id":"1"},{"data.formList.IdentificationDetails.Visit_No":"1"}).li
mit(1)
 
I want to use this query in entity framework.
 
[HttpGet]
public object getFrequencyQuestionData()
{
var connectionString = "mongodb://localhost:27017";
MongoClient client = new MongoClient(connectionString);
MongoServer server = client.GetServer();
MongoDatabase db = server.GetDatabase("FormDataBase");
MongoCollection collection = db.GetCollection<Blog>("FrequencyQuestionForm");
// Here i want to call that query .. 
MongoCursor<Blog> cursor = collection.FindAllAs<Blog>();
var count = collection.Count();
string document = cursor.ToJson();
JToken token = JToken.Parse(document);
var jObject = JObject.FromObject(new { formdata = token, count });
return jObject;
}

Brought to you by:

Answers (1)