arrays


MongoDB index on a key/value document in an array in a document in an array always scans all documents


I am doing a proof of concept with MongoDB. I have a document that has a complex structure. I am able to easily search on it, but the search is becoming slow. I am wondering if I can build any index on my collection. The real object is more complex, but this is the minimal example that shows the problem. The data is not real, I just generated a million documents with some values set from a counter.
> db.records.findOne()
{
"_id" : ObjectId("591a92bd330f72395c3ecb9c"),
"recordId" : "T1-C450",
"episode" : [
{
"episodeDate" : NumberLong("1494913725568"),
"data" : [
{
"key" : "sequence",
"value" : "A450"
},
{
"key" : "alternativeSequence",
"value" : "X450"
}
]
},
{
"episodeDate" : NumberLong("1494913725568"),
"data" : [
{
"key" : "sequence",
"value" : "B450"
},
{
"key" : "alternativeSequence",
"value" : "Y450"
}
]
}
]
}
I am searching documents by:
> db.records.find({"episode.data.key":"sequence", "episode.data.value":"B450"})
I have tried the following index that is used for the search above:
> db.records.createIndex({"episode.data.key":1, "episode.data.value":1})
However when I run explain query:
> db.records.find({"episode.data.key":"sequence", "episode.data.value":"B450"}).explain('executionStats')
...it seems like the index returns everything.
"stage" : "IXSCAN",
"nReturned" : 1000000,
And the total time to run the query is longer than when the index is not used.
Is there any better way of indexing the key-value pairs in the nested array as in the example above? Is it possible?


Related Links

Efficient way of computing the Greatest Common Divisor from an Array - Swift [duplicate]
Read from array1 write from array2
Type Mismatch in Array
Subtracting from each element in array in python
C# Problems importing a file to an array and put each character in it's own index
How to identify the position of a sequence of elements in an array in bash
Combine values of two arrays to form key and values to hash in ruby [duplicate]
Create array with key from dict with sorted by dict values
How do I convert every element in an array to its own array?
Adding a list to an array from different file format in perl
How to use Perl `sort` and `pairwise` if I already have variables `$a` and `$b`
Sum dynamic part of array values Excel VBA
Ada How to get input a list of integer from a user and put it into an array
count occurences in for loop
Update / create subdocument in array
Delphi: const list of const objects [duplicate]

Categories

HOME
google-apps-script
sass
google-cloud-bigtable
thunderbird-addon
console
gspread
iis-7.5
ng-admin
slim-3
unity2d
powershell-v3.0
cortex-a
wysiwyg
cs-cart
dlib
line-api
spring-cloud-config
zope
jpeg2000
android-fragmentactivity
uiautomator
dspic
rworldmap
fabric
hash-collision
image-quality
web-frontend
vcard
gzip
mangodb
superagent
invoke-command
backup-strategies
google-drive-realtime-api
mapguide
powershell-remoting
soundjs
jrules
distributed-transactions
aqgridview
mouseclick-event
chrome-remote-desktop
iphone-developer-program
python-hypothesis
sqlexception
glkit
mailcatcher
bacnet
pax-web
freetype2
boost-hana
ng2-material
remoteapp
dac
fortran90
app.xaml
textkit
achartengine
pyopengl
graphical-logo
sparse-file
uos
virus
jython-2.7
orientation-changes
rhel5
node-inspector
outline
io.js
planetary.js
ifft
json-patch
baucis
magicalrecord-2.2
onselect
jqmobi
windows-update
ienumerator
dynamics-ax-2009
resgen
reporting-tools
template-haskell
entity-framework-ctp5
msgbox
serp
ihttphandler
squeel
yajl
hmacsha1
virtualquery
visual-studio-dbpro





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android


MS Developer
developer works
python
ios
c
html
jquery


RDBMS discuss