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

$hint does not work with $natural as a modifier

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.11.1
    • Component/s: Read Operations
    • None

      So, based on .hint() and $hint official documentation, I'm using this query on terminal:

       

      db.Logs.find()._addSpecial( "$hint", { $natural : -1 } )
      

       

       

      The closest I was able to produce on C# was something like:

       

       

      var options = new FindOptions
                  {
                      Modifiers = new MongoDB.Bson.BsonDocument("$hint", "{ $natural : -1 }")
                  };
      
      //let me check the "translation"
      var str = logCollection.Find(obj => true, options).ToString();
      
      return logCollection.Find(obj => true, options).ToList();

       

      This code throws the exception:

       

      planner returned error :: caused by :: hint provided does not correspond to an existing index.'
      

       

      But, the '.ToString()' method does seems to translate the command correctly:

       

      find({ })._addSpecial("$hint", "{ $natural : -1 }")

       

      So, if ToString() is getting it correctly, it should work, but it isn't.

       

      On that note, shouldn't you create an C# equivalent to find().hint(index) to make it simpler to use hint ?

       

       

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            caiocsl@gmail.com Caio César S. Leonardi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: