简体   繁体   中英

How to log results to console with MongoDB 3.0 c# driver

I am writing the simple c# console program to connect mongodb db instance and get the value from the mongodb and need to display console window. I am using mongodb version 3.0.

I am getting date but not able display console. I am getting struck with syntax.

Any one please help me, I have shared my sample code below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB;
using MongoDB.Driver;
using MongoDB.Bson;
using MongoDB.Driver.Linq;
namespace MongoCHash
{
    class Program
    {
        static void Main(string[] args)
        {
            var mongod = new MongoClient();
            var db=mongod.GetDatabase("MyDB");
            var movies = db.GetCollection<Movie>("movie");


        }
    }

    public class Movie
    {
        public ObjectId Id { get; set; }
        public string name { get; set; }
    }
}

You have got a Movie object collection you need to iterate over the collection and the do a Console.Log() of what ever property of the movie object you want including date. If you want I can post an example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM