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

mongo search for part of string match in words array
How to use an OR clause to filter an array in Swift
Why accessing this json sub elements by index raises this error?
How to apply WorksheetFunction.Average to a dynamic array in VBA
Getting array length in mongodb?
using vb.net and LibTiff to convert large tiff images
Storing the output of spap2 into an array then looping and graphing that output
Using intermediate variable to work with array (reference type)
Swift Creating tableView From JSON
How how convert normal string into multi-line string
How to convert a double to double array?
Use one index from array
ko.observableArray not UI not UPdating.
Creating collection of different enums
Determine Winter or Summertime due to month (UTC Timezone) [duplicate]
UDF if value is in array - Type Mismatch from a prior answer - IsInArray

Categories

HOME
makefile
converter
security
bower
laravel-5.3
ubuntu-16.04
steam
json-ld
windows-store-apps
apple-numbers
gspread
jframe
google-spreadsheet-api
xamarin-studio
data-synchronization
abcpdf
store
phoenix
arm-template
grub2
anychart
jsonserializer
esql
restfb
novnc
logarithm
samsung-mobile
python-textprocessing
emv
data-conversion
datadog
jackson-dataformat-csv
edb
geopy
reactivemongo
phpspreadsheet
passenger
sidr
pace
rider
readfile
parse-android-sdk
elfinder
polyfills
web-development-server
taglib
mod-fcgid
uiviewpropertyanimator
openh264
android-bitmap
heroku-postgres
cdk
redux-router
pdfkit
objloader
push-diffusion
backstop.js
tomee
update-site
children
dbscan
twgl.js
axes
bluesnap
approval-tests
acm
throughput
optionbutton
hornetq
site-prism
matcaffe
kendo-menu
abas
harp
type-mismatch
criteria-api
coypu
apache-mina
guzzle6
inputaccessoryview
node-inspector
sgml
voldemort
config-files
broadcasting
android-json-rpc
windows-update
grunt-contrib-compass
pep8
trailing-slash
dropdownlistfor
mpmovieplayer
die
hashalgorithm
django-nose
phpcrawl
clients
boost-date-time
multibyte-functions
web-statistics
usability-testing

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