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

How to parse dynamic object in mvc?
Chomp doesn't work with perl script
VB and general logical undarstanding
How to select options based on character user input stored in an array in C?
Remove duplicate array elements with O(N) by not using collections? [duplicate]
Calculate the derivative of a vector
How to assign excel cell with string to array value in visual basic?
python 3 read array (list?) into new values
Decrypt an array of strings in vb.net
bash array with new line as IFS
create new object in array (which is in a object which is in an array which is document) in meteor/mongodb
Initializing an array of records in VHDL
Perl Array and Hash references Handling
Separating digits in decimal representation of integer
How do I return an array from an array function using groovy?
Perl - Reading two files to compare contents

Categories

HOME
cluster-computing
plsql
elixir
shopify
project-management
system-verilog
mapping
warnings
ipython
puppet
amazon-product-api
parse-server
bibtex
couchdb-2.0
sequelize.js
jpanel
xcode8.3
metronic
oclint
mongodb-query
titan
opera-mini
python-unicode
arm-template
grub2
thumbnails
cython
novnc
activepython
samsung-mobile
cgal
i3
fileinfo
gpib
protobuf-net
smart-mobile-studio
threshold
service-locator
passenger
windows-10-iot-core
sidr
pace
office365connectors
polyfills
restful-url
productivity
control-flow-graph
jrules
startapp
jtds
production-environment
dimple.js
gd
jags
shutdown
hpcc
iron.io
kendo-combobox
asp.net-mvc-partialview
usb-drive
multinomial
python-winshell
webhdfs
mptcp
vine
leadtools-sdk
harp
digits
shift-jis
ctrlp
named-ranges
microblaze
ember-components
jstat
ghostdoc
valence
spdy
lumx
delphi-xe3
zipalign
uipickerviewcontroller
sanitization
windows-mobile-6
fogbugz-api
nservicebus4
html-form-post
pep8
client-library
xml-libxml
domain-calculus
lync-server-2010
radchart
scrollto
plone-funnelweb
unions
flexicious
throttling
revert
file-encodings
google-instant
rd

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