indexing - How does mongodb index lists -


for example: if had db collection called stores, , each store document has list of items sell, , stores share items, how mongodb build index on that? build btree index on possible items , on each leaf of tree (each item) reference documents contain it?

background: i'm trying perform queries using index:

db.store.find({merchandise:{$exists:true}}) // 'merchandise' list db.store.find()[merchandise].count() 

would index on 'merchandise' me? if not, option creating separate meta field on 'merchandise' size, , index that?

schema:

{ _id: 123456,   name: macys   merchandise: [ 248651234564, 54862101248, 12450184, 1256001456 ] } 

from document sample if build index on merchandise multikey index , index on every item on array. see multikey indexes section in here.

if merchandise array of subdocuments, indexing on merchandise put index on field of subdocument in array. index can make queries db.store.find("merchandise":248651234564) , retrieve document having merchandise 248651234564

for getting count of merchandise, can size of merchandise field of 1 document db.store.find()[index].merchandise.length. creating seperate field on merchandise size , indexing feasible option, if want run queries based on merchandise size.

hope helps


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -