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

drop and trim a list in aerospike udf
Passing arrays as smaller than they actually are
Creating list from array elements, making sequence of numbers
Pascal Arrays Can't figure out how to print info from arrays
Arrays with negative indices in FreePascal
MongoError: exception: Cannot apply the positional operator without a corresponding query field containing an array
Delete sheets if their names belong to an array
Delphi - Re-split an array of string?
Split a String array after X number of comma
Searching with filter, not working correctly - Parse, Swift
addToSet if not already present
How to convert group of numbers in text file into matrix array
How to create a reverse sort on an Excel array
Deeply-placed array contents were missing
Difference between [String] and Array<String>
Split a numpy array by a key array

Categories

HOME
converter
security
sass
google-cloud-bigtable
elixir
dynamics-crm
itext
antivirus
facebook-graph-api
angular2-routing
json-ld
otrs
visualization
safari
apache2
websphere-liberty
powershell-v3.0
keystore
camera-calibration
finite-group-theory
ctypes
store
simple-injector
symfony2-easyadmin
zend-framework-mvc
multiple-columns
uiautomator
google-maps-android-api-2
apply
countif
jquery-form-validator
ghost-inspector
tarantool
samsung-mobile
java-ee-7
visual-c++-2017
net-snmp
mef2
system.data.sqlite
fileinfo
datadog
spring-profiles
spreedly
nsurlconnection
modulo
node-horseman
powershell-remoting
windows-10-iot-core
lego
nlb
nodeclipse
rhel.net
parse-android-sdk
sql-like
mongoexport
tic-tac-toe
react-native-router-flux
ivona
amazon-clouddrive
onmouseover
range-v3
azureportal
restivejs
activeweb
try-finally
bacnet
nofollow
qt-linguist
fill
eml
asp.net-mvc-2
anythingslider
throughput
function-fitting
enyo
application-loader
retro-computing
prezto
gulp-livereload
searchkick
word-2013
sqoop2
line-numbers
and-operator
vcl
system.web
phpdocx
anjuta
facebook-chat
nscolor
dynamics-ax-2009
dwolla
android-contextmenu
mozart-mvc
getusermedia
zookeeper
easygui
gtk2hs
dcpu-16
scalaxb
adsl
port-scanning
phpcrawl
smooth
email-spec
getresource
hardware-acceleration
quick-search
pci-bus
divx
document-library

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