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

Algorithm: Finding max subset of elements in array
How to make array distinct
Swap arrays in Ruby
Quick way to copy elements in a 2D array
It's better to use array or object to store structured data?
Morton Encoding Z-indexing Space Usage
How to Remove Duplicate values in array in c#
Actionscript, hasOwnProperty() of multidimensional arrays
Labview : numbering color box array
Replace values of one column of matrix size 1*n to another matrix of size n*n
How to query a single embedded document in an array in MongoDB?
Pushing Sound files to an Array with Swift
Alamofire : Updating array's values with JSON's data
Issues with arrays, how would i go about solving this?
Traverse through an array with missing elements and report those missing elements in shell
Is it possible to send an object to a Chunk instead of an array

Categories

HOME
converter
crate
npm
backup
cpu-architecture
json-ld
avro
mapbox-gl-js
extract
docker-swarm
mainframe
orientation
yocto
filter
apiconnect
docker-windows
shader
ng-admin
ssr
automata
postmessage
uisplitviewcontroller
zope
arraylist
derived
jpeg2000
zend-framework-mvc
mousewheel
ip-camera
tweets
dspic
remove-method
rworldmap
azure-servicebus-queues
jquery-waypoints
npm-install
iis-10
geopandas
codelite
mayavi
websauna
vegan
pari
postgresql-9.2
preg-grep
spring-insight
hotmail
hawtio
passenger
haskell-pipes
active-model-serializers
linq-to-entities
html-agility-pack
pdftk
g1gc
lftp
mod-fcgid
dojox.grid.datagrid
etherpad
redux-router
sql-import-wizard
system.web.ui.webcontrols
alter
rstudio-server
update-site
instruments
unsatisfiedlinkerror
magento-1.4
android-cursoradapter
intellitest
hornetq
matcaffe
p-np
fabric-twitter
calibration
leadtools-sdk
rx-groovy
viper-architecture
findcontrol
isml
apache-mina
xaml-designer
hg-git
pl-i
kallithea
mser
livechat
docopt
winrt-httpclient
backbone-relational
dynamics-ax-2009
sametime
mvccontrib
usn
blockingqueue
isolatedstorage
file-exists
jpf
port-scanning
rijndael
msn
recordset
hibernate3-maven-plugin
task-management
scala-2.8
swfloader
hmacsha1
evb
msf
dotproject

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