sql >> Databasteknik >  >> NoSQL >> MongoDB

MongoDB-index och $or-operatorn

Ja, en $or-fråga kommer att använda index efter behov. Till exempel:

> db.test.ensureIndex({a:1})
> db.test.ensureIndex({b:1})
> db.test.find({$or:[{a:1}, {b:2}]}).explain()
{
        "clauses" : [
                {
                        "cursor" : "BtreeCursor a_1",
                        "nscanned" : 0,
                        "nscannedObjects" : 0,
                        "n" : 0,
                        "millis" : 0,
                        "nYields" : 0,
                        "nChunkSkips" : 0,
                        "isMultiKey" : false,
                        "indexOnly" : false,
                        "indexBounds" : {
                                "a" : [
                                        [
                                                1,
                                                1
                                        ]
                                ]
                        }
                },
                {
                        "cursor" : "BtreeCursor b_1",
                        "nscanned" : 0,
                        "nscannedObjects" : 0,
                        "n" : 0,
                        "millis" : 1,
                        "nYields" : 0,
                        "nChunkSkips" : 0,
                        "isMultiKey" : false,
                        "indexOnly" : false,
                        "indexBounds" : {
                                "b" : [
                                        [
                                                2,
                                                2
                                        ]
                                ]
                        }
                }
        ],
        "nscanned" : 0,
        "nscannedObjects" : 0,
        "n" : 0,
        "millis" : 1
}


  1. Hur hanterar man pagineringsfrågor korrekt med mongodb och php?

  2. Data null efter att ha sparat entitet med Moongose ​​och GraphQL

  3. Stöd för flera användartyper av Passport-lokal mongoose node.js

  4. Kan inte hitta modulen 'socket.io/node_modules/redis'