Mongodb driver C# Index not used

Asked

Viewed 19 times

1

In Mongodb:

db.estr.createIndex({_id:1, Atualizar:-1});

In C#

var a = await db.dados.Distinct(x=>x.codigo).toListAsync();
var b = await db.estr.find(x=>!a.contains(x._id) && x.Atualizar).toListAsync();

Index Stats

{
    "name" : "_id_1_Atualizar_-1",
    "key" : {
        "_id" : 1.0,
        "Atualizar" : -1.0
    },
    "host" : "OMNIIS2012HOM:27017",
    "accesses" : {
        "ops" : NumberLong(0), <----- not utilizade
        "since" : ISODate("2020-03-24T11:00:25.011-03:00")
    }
}

x.Upgrading is Boolean

1 answer

0

I got the answer you solved here

Since _id is denied it scans, then ideally create the Update/_id index

db.estr.createIndex({Atualizar:-1, _id:1})

This way it looks for Update and scans only those who fulfill this condition, getting much faster than doing first by _id.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.