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

Three dimensional matrix, Cartesian product
Sort an array but only the first X number of items in ActionScript?
Perl while loop won't exit when blank line is entered
Using += in scriptblock for a switch statement in a foreach loop
using a set of vectors in a root searching algorithm
How to pass elements to a different cell array given a specific condition
Excel lookup in multiple column array, return row
Swift optional Array property is immutable?
How to convert unsigned char * to byte array in cli/c++
Row and Column Indices for 2-D array in Matlab
Perl reading file, printing unique value from a column
RISC String array
How do I increment my array counter to move to the next element in the array in this code?
Powershell: Add lines to a custom objects
Dimension-wise logical indexing in a 3D array
Referencing Ranges in Arrays

Categories

HOME
symfony
project-management
vhdl
warnings
raspbian
ubuntu-12.04
yocto
tizen-wearable-sdk
currency
openwrt
google-classroom
qt-installer
mongodb-query
viber
rapidjson
aspell
uicollectionview
boolean-expression
ios10.3
cython
jni
uiautomator
google-ima
tfs2013
net-snmp
ui5
interrupt-handling
edge-detection
dd-wrt
vegan
spring-insight
pljson
mapguide
strstr
mongoexport
brute-force
cross-entropy
react-native-router-flux
distributed-transactions
paho
matlab-cvst
dojox.grid.datagrid
automator
production-environment
uiviewpropertyanimator
gauss
seamless-immutable
goquery
jgraph
multi-agent
windows-95
mbaas
forerunnerdb
mercury
keycode
icefaces
mongoose-populate
cron-task
nofollow
soda
ng2-material
image-editing
kendo-combobox
mpeg-4
servlet-3.0
android-cursoradapter
enyo
ninject.web.mvc
code-readability
evo
lmfit
built-in
base32
ffserver
isml
belongs-to
alphablending
odftoolkit
and-operator
livechat
power-law
argument-passing
slick-2.0
late-static-binding
circos
bsod
fogbugz-api
layered
justgage
adomd.net
fortran77
pascals-triangle
vt100
domain-calculus
mvccontrib
blockingqueue
javascriptserializer
gjs
jpf
concurrent-programming
msgbox
objectbrowser
throttling
qtembedded
goliath
cookieless
smooth
squeel
email-spec
chatroom
boost-date-time
filetime
openwysiwyg
soft-keyboard

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App