MongoDB索引相同键的不同数据类型

man*_*nth 3 mongodb mongodb-indexes

假设我有三个文件,其中存在"B"字段.这三种都有3种不同的数据类型.索引BTREE如何存储?将"B"作为索引键是有效的吗?

例.

{_id:"1",a:1,b:"abc" }        //B is string here 
{_id:"1",a:1,b:[1,2,3] }      //B is array of numbers
{_id:"1",a:1,b:{x:1,y:"a"} }  //B is another nested document
Run Code Online (Sandbox Code Playgroud)

wdb*_*ley 5

它没有任何不同,如果它们都是相同的类型.它的效率并不比它们都是同一类型的效率更高或更低.只要知道排序将如何工作 - BSON类型排序将比较不同的类型.