I can see MongoDB chose to use COLLSCAN instead of using the index IXSCAN. In my case because the url value I passed is a string, and it should be covered by the index. Why does mongo choose to do a full COLLSCAN ?
However, I am wondering why do we need to pass the type explicitly. MongoDB should be start enough to infer that the type of “mongo” is a string, because on the above unique key example, if we do the insertion:
db.website.insert({url: "mongo"})
MongoDB can infer the type of “mongo” is a string because it needs to ensure the key’s uniqueness. If MongoDB can infer the type for insertion, why can’t it infer the type for querying?
the results may include documents with url as a Symbol, which is not covered by your index. For that reason, MongoDB driver will not use the index in this case.