views:

33

answers:

2

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&gt;" ,
              "predicate" : "<http://example.org/predicate&gt;" ,
              "object" : "<http://example.org/object&gt;"
            }
          ]
}
+2  A: 

You cannot have dots in keys.

The driver should reject this before it gets to the database.

Thilo
Yes, this bug (reported by me) will be fixed in 2.3.
tszming
Will report a bug for my relevant driver
RobV
+1  A: 
lanwin