Query from MongoDb Collection

Introduction

This blog gives code sample to query document from mongodb collection.Querying from mongodb collection is same as query from collection in linq. it is very is to query document or documents from mongodb collection.

Start


Query a single document from collection
  1. MongoCollection symbolcollection = database.GetCollection<Symbol>("Symbols");  
  2. Student et = symbolcollection.AsQueryable<Student>().Where<Student>(sb => sb.Name == "Kailash").SingleOrDefault();  
 
Query List of document from Collection
  1. MongoCollection symbolcollection = database.GetCollection<Symbol>("Symbols");    
  2.  List<Student> query = symbolcollection.AsQueryable<Student>().Where<Student>(sb => sb.Name == "Kailash").ToList();  

Ebook Download
View all
Learn
View all