Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1327

Mongo Database queries in c#.net

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.0.1
    • API
    • Windows

    Description

      I am using Mongo CSharpDriver-2.0.0 version and IMongoCollection Async in my application. My data collection looks as shown in the figure attached(2.png).
      Here I want to perform a Search operation on Categories, basically we will give comma separated list of Category Names and it should return a list of Records that are matching the categories that are provided as input.
      To implement above functionality I am using the below code: This code works fine when I pass a single category.

      var collection = _database.GetCollection<BusinessDeal>("BusinessDeals");
      var filter = Builders<BusinessDeal>.Filter.Eq("Categories.CategoryName", categorylist) | Builders<BusinessDeal>.Filter.Eq("Accessgroups.AccessgroupName", groups);
      var result = await collection.Find(filter).ToListAsync();

      But my requirement is to get the records when I provide a Comma separated categories List. For that implementation I have implemented the following code:
      var collection = _database.GetCollection<BusinessDeal>("BusinessDeals");
      var filter = Builders<BusinessDeal>.Filter.AnyIn("Categories.CategoryName", categorylist.Split(',').ToArr()) |
      Builders<BusinessDeal>.Filter.AnyIn("Accessgroups.AccessgroupName", groups.Split(',').ToArr());
      var result = await collection.Find(filter).ToListAsync();
      The above code is not returning any results and throwing error as “Not Yielded any Results” and Status message as “Failed”.

      Attachments

        1. 2.png
          2.png
          65 kB

        Activity

          People

            Unassigned Unassigned
            arvindachary.n@sparshcom.net Arvind Chary
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: