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

If a cell in Excel contains an array formula (like `={1,2,3}`) can I extract the elements of the array with VBA
Why doesn't fortran iterate over strings
Compute Bell numbers in Matlab
Output for merged array of hashes
mapping strings to array in MATLAB
Go-lang: How to convert slice to fixed size array?
C# Convert Json array to string array using Json.Net
Making a Matrix element equals the row number times the column number in matlab [duplicate]
Angular Js - ng-repeat over array of array objects
AS3 Flash - How to remove dynamically created MovieClip from different function?
access hash member of type array within array of hashes
Generating matlab array from union and replacement of two arrays
How to search an element in a sorted 2-D array with order (n)?
Ordering of array dimensions
Trying to declare an array of a certain size in Scala
Select pairs from an array (matching game) And add sound to that selection AS3 Flash CS4

Categories

HOME
google-apps-script
ssas-2012
elixir
xamarin.android
freepascal
facebook-graph-api
translation
reportportal
thunderbird-addon
formal-verification
propertygrid
tizen-wearable-sdk
data-science-experience
onenote-api
metronic
ndis
rfid
abcpdf
automata
qt-installer
phoenix
sign
react-leaflet
rebol2
uisplitviewcontroller
bar-chart
android-toolbar
apache-karaf
jive
google-maps-android-api-2
extractor
myob
logarithm
helper
hana-studio
devforce
encase
hotmail
geopy
fabric-digits
reactivemongo
superpowered
sidr
nodeclipse
pmwiki
code-behind
image-compression
silverlight-3.0
bing-translator-api
openweathermap
onmouseover
dimple.js
seamless-immutable
jgraph
windows-95
mercury
unity3d-editor
addin-express
gmt
backstop.js
selecteditem
scriptlet
amazon-kcl
eml
license-key
hyperthreading
mirrorlink
mysqldumpslow
wif
ffserver
digits
coypu
robocode
em
sthttprequest
csplit
system.web
phpdocx
initialization-vector
visual-studio-addins
facebook-chat
java.util.date
convex-polygon
driver-signing
trimming
vmware-server
cbcentralmanager
osi
blockingqueue
cadisplaylink
hibernate3
makefile-project
supersized
point-sprites
hashalgorithm
handwriting
scalaxb
smooth
junit3
adobe-contribute
task-management
winverifytrust
kpi
system-codedom-compiler

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