0

Hi I am a newbie on MongoDB and CosmosDB and I try to this in c#

MongoClientSettings settings = MongoClientSettings.FromUrl(
                      new MongoUrl(connectionString)
                    );
                    settings.SslSettings =
                      new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 };    
    var mongoClient = new MongoClient(settings);
    var mongoDatabase = mongoClient.GetDatabase("MYDATABASE");
    var mongoCollection = mongoDatabase.GetCollection<BsonDocument>("MYCOLLECTION");

    var builder = Builders<BsonDocument>.Filter;            
    var filter = builder.Lt("mac", "001BC50670101BB8") & builder.Gte("date", "2016-09-18T00:00:00Z") & builder.Gte("date", "2017-09-22T00:00:00Z");

    var query = mongoCollection.Find<BsonDocument>(filter).ToList<BsonDocument>();

But when it runs the query on the server I get this error:

Errors":["An invalid query has been specified with filters against path(s) that are not range-indexed. Consider adding allow scan header in the request."

I have found that I should add the "x-ms-documentdb-query-enable-scan" header to my request. But how I can do this?

5
  • Maybe Mongo dosen't know what is less than 001BC50670101BB8? Commented Sep 21, 2017 at 8:27
  • oh... damn. thanks it should be eq and solves the problem Commented Sep 21, 2017 at 8:40
  • does it work now? Commented Sep 21, 2017 at 8:40
  • yes was the error in the query thanks Commented Sep 21, 2017 at 8:49
  • I'll post it as answer so we can close question. Commented Sep 21, 2017 at 8:50

1 Answer 1

2

Solution found in comment section:

Query changed from

builder.Lt("mac", "001BC50670101BB8")

to

builder.Eq("mac", "001BC50670101BB8")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.