3

Suppose I have a three documents where "B" field is present. All the three have 3 different datatypes. How the Index BTREE is stored? And making "B" as an index key is efficient?

Example.

{_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
manikawnth
  • 2,739
  • 1
  • 25
  • 39

1 Answers1

5

It doesn't work any different than if they are all the same type. It's not any more or less efficient than if they are all the same type. Just be aware of how sorting will work- different types will be compared by the BSON type ordering.

wdberkeley
  • 11,531
  • 1
  • 28
  • 23