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

UnityScript treat Vector3 array as Collections.Array
Non contiguous ranges into monodimensional array
How to convert an array to a hash with specified common values
How can I find all the cells that have the same values in a multi-dimensional array in octave / matlab
Collecting Multiple Properties Of An Object To An Array
Sublime regex comma replace character
textscan returning empty cell array
Is there a way to initialise an array using an expression/function in R
How are these arrays being used in this Fortran algorithm?
How to assign an array to a row of 2d array in Scala
logstash extract matched strings into array
A class contains an array of objects. Do I need to set each of them to nothing on terminating the containing class?
remove items from array not working
Split Function using an Excel row as delimiter
AS3 Array issue and Arduino
Google apps script - get A1 cell notation of each element in an array

Categories

HOME
spring
pug
erlang
redis
webrtc
decorator
amazon-product-api
command
matplotlib
search-engine
vlc
recyclerview
specflow
propertygrid
xtext
sequelize.js
data-science-experience
mongodb-query
pdo
atlassian-plugin-sdk
flat-file
jsonserializer
vs2017
tweets
url.action
apply
tcpclient
tarantool
extractor
nmf
iis-10
tampermonkey
sumo
visual-c++-2017
onesignal
rhandsontable
metadata-extractor
mangodb
large-data
precedence
pox
broadleaf-commerce
autocompletetextview
sonarqube-scan
poco-libraries
declare
code-behind
wcf-security
jupyter-console
pdftk
intersystems-ensemble
finite-element-analysis
stress-testing
php-ews
appstore-approval
uiviewpropertyanimator
jags
broadcast
bnd
selenium-firefoxdriver
opencpu
festival
efxclipse
libreadline
pydio
gameanalytics
bacnet
listadapter
dbscan
scriptlet
mpeg-4
usb-drive
asymptote
file-diffs
affix
lmfit
kendo-menu
rad
leadtools-sdk
viper-architecture
gulp-livereload
epl
jazz
hiera
named-ranges
kendo-mvvm
ibmsbt
sortable
firebug-lite
mov
korma
indexing-service
zipalign
broadcasting
mimosa
healthvault
facebook-chat
trimming
installshield-2009
swrl
argb
mstsc
soa-suite
fluidsynth
arbor.js
attachevent
moq-3
sunspot-rails
cadisplaylink
wcf-web-api
concurrent-programming
electronic-signature
ou
coff
collect
gwt-2.2-celltable
jquery-ui-button
mvvm-foundation
virtualquery
web-analytics-tools
visual-studio-dbpro





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