I'm having a problem getting indexes in MongoDB to work correctly when I'm indexing into embedded documents. The indexes work fine if the inner key is a simple string but because of my data format the inner keys often need to be URIs and this doesn't seem to work, looking at the Mongo log when I try and create the indexes it says the indexes are created but it adds every document to the index.
Is there a reason why indexes on property names of this type does not work and what can I do to avoid this issue?
Example Document
{
name: "some-name",
graph:
{
"http://example.org/subject" :
{
"http://example.org/predicate" :
[
{ "value" : "http://example.org/object", "type" : "uri" }
]
}
}
}
Alternative Schema which avoids the Issue
I've now changed my code to use an alternative schema which avoids this issue since the URIs are now always values rather than property names and the schema allows me to leverage multikey indexes in MongoDB properly:
{
name : "some-name",
graph : [
{
"subject" : "<http://example.org/subject>" ,
"predicate" : "<http://example.org/predicate>" ,
"object" : "<http://example.org/object>"
}
]
}