Saturday, November 16, 2019

Get records from MongoDB using Asp.net.

To get the records from MongoDB using Asp.net.

using MongoDB.Bson;
using MongoDB.Driver;         
                              
static MongoClient client = new MongoClient("mongodb://localhost:27017"); //Set the connection string

static IMongoDatabase db = client.GetDatabase("test"); //Database name
     
 public void List()
  {

    IMongoCollection<BsonDocument> collection = db.GetCollection<BsonDocument>("user"); //table name

    var filter = Builders<BsonDocument>.Filter.Empty; //It behaves like select * from user

    var res = collection.Find(filter).ToList();
              
 }

No comments:

Post a Comment

Git Commands

Git Version   To check the git version Git -v       Git Clone To clone the repository, use the following command: Git clone [u...