C # Syntax Syntax Syntax # MongoDB

I am trying to get individual values ​​from a field in MongoDB. I have real syntax issues. Using mongoshell, this is relatively easy to do, this is the query that I run:

db.cmstest.distinct("categories") 

This query returns an array of strings with all individual values.

Now I'm trying to get the syntax correctly using the latest official MongoDB drivers, but not for success. This is my code that was unsuccessful:

 var categoriesList = await blogContext.Articles.DistinctAsync<List<string>>("categories", ""); 

Note: List<string> categories.

Can anyone help shed some light? I tried to look both in the documentation and on the Internet and did not find much.

Thanks in advance.

+5
source share
1 answer

You can try the following approach:

 var filter = new BsonDocument(); var categoriesList = await blogContext.Articles.DistinctAsync<string>("categories", filter); 
+7
source

Source: https://habr.com/ru/post/1244221/


All Articles