简体   繁体   中英

How to get from a list<T> in C# from a document in MongoDB to

Here is my code:

    using MongoDB.Bson;
    using MongoDB.Driver;

    public List<Teacher> GetTeachersFromMongoDB()
    {
        client = new MongoClient();
        database = client.GetDatabase("SchoolManagement");
        var collection = database.GetCollection<BsonDocument>("ListTeachers");
        var document = collection.Find(new BsonDocument()).ToList();
        var cursor = collection.Find(new BsonDocument()).ToCursor();
        return teachers;
    }

And i want to do something to return value type List for this function. Please help me!!! Thank you :)

I assume you have a Teacher object, so I think you should use

var collection = database.GetCollection<Teacher>("ListTeachers");

instead of

var collection = database.GetCollection<BsonDocument>("ListTeachers");

And I don't get, where your return value comes from, but if you return 'document' it should work

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