I am unsing Mongo DB and C# (.Net) to build my web application. I want to run Mongo queries in my .Net application like SQL queries using ADO.net. What are the possible ways to run direct Mongo queries in C# ?
Asked
Active
Viewed 1,824 times
0
-
Possible duplicate of [MongoDB Stored Procedure Equivalent](https://stackoverflow.com/questions/3876049/mongodb-stored-procedure-equivalent) – dnickless Oct 18 '17 at 20:20
1 Answers
2
I think your definition of a MongoDB query is something like this:
{"Name": "Name 1"}
That is a valid json, if yes try below code in C#:
// `queryString` is a MongoDB query in json format
var queryString = @"{""Name"": ""Name 1""}";
// `query` is a `BsonDocument` generated by `queryString`
var query = BsonDocument.Parse(queryString);
// You can use `TryParse()` also ...
// Now you can use that `query` in `Find()` like this:
var result = await col.Find(query).ToListAsync();

shA.t
- 16,580
- 5
- 54
- 111