How to fetch specific data from the collection using mongo query using asp.net core

Viewed 176

How to fetch specific data from the collection using mongo query using asp.net core.

            var Client = new MongoClient(connectionString);
            var dbName = Client.GetDatabase(databaseName);
            var collection = dbName.GetCollection<BsonDocument>(collectionName);
            var res = collection.Find({},{_id:0,name:1}).ToList();

The error is:

String contains extra non-whitespace characters beyond the end of the document.

1 Answers

Try to change

var res = collection.Find({},{_id:0,name:1}).ToList();

to

var res = collection.find({},{_id:0,name:1}).ToList();

Use find rather than Find.

Related