0

Simple queries are not working on my mongodb database.

When in the console I run

db.quads.find({});

I get all the documents in the 'quads' collection, one of which is:

{ "subject" : "u:http://dbpedia.org/resource/Tim_Berners-Lee", "predicate" : "u:http://dbpedia.org/ontology/abstract", "object" : "l:\"Sir Timothy John Berners-Lee KBE, OM, FRS (TimBL ou TBL) é um físico britânico, cientista da computação e professor do MIT. É o criador da World Wide Web, tendo feito a primeira proposta para sua criação em março de 1989. Em 25 de dezembro de 1990, com a ajuda de Robert Cailliau e um jovem estudante do CERN, implementou a primeira comunicação bem-sucedida entre um cliente HTTP e o servidor através da internet. Berners-Lee é o diretor do World Wide Web Consortium (W3C), que supervisiona o desenvolvimento continuado da web. Também é o fundador da Fundação World Wide Web e é um pesquisador sênior e titular e fundador da cadeira de 3Com no Laboratório de Inteligência Artificial e Ciência da Computação do MIT (CSAIL). É um diretor da The Web Science Research Initiative (WSRI) e um membro do conselho consultivo do Centro de Inteligência Coletiva do MIT. Em abril de 2009, foi eleito como membro da Academia Nacional de Ciências dos Estados Unidos, sediada em Washington, D.C. Em 2004, Timothy venceu o Millennium Technology Prize, o que lhe rendeu um milhão de euros.\"@pt", "graph" : "u:http://example.org/people", "_id" : ObjectId("5134aa893fff1d490400009c") }

One would expect that running a query like this...

db.quads.find({"subject" : "u:http://dbpedia.org/resource/Tim_Berners-Lee"});

... I would get at least one document, since there IS a document with a "subject" field with the value 'u:http://dbpedia.org/resource/Tim_Berners-Lee'.

But I get nothing... I tried wildcard querying also:

db.quads.find({"subject" : "/.*Tim_Berners-Lee.*/"});

To no avail... What am I doing wrong?

Thanks!

MPelletier
  • 16,256
  • 15
  • 86
  • 137
João Rocha da Silva
  • 4,259
  • 4
  • 26
  • 35
  • 1
    You have `"` around your wild cards, aka they will be read as strings not regexs, is there really a `u:` before the field value or is that something your client side programming shows? – Sammaye Mar 05 '13 at 15:57
  • I tried removing the "" around the wildcards, didnt work. Even non-wildcard queries return nothing: > db.quads.find({"subject" : "u:http://dbpedia.org/resource/Tim_Berners-Lee"}); > The u: is part of the value of the field, no mistake there. – João Rocha da Silva Mar 05 '13 at 16:00
  • 1
    Hmm...the query by `subject` you show does return the doc for me. – JohnnyHK Mar 05 '13 at 16:05
  • Johnny what is your version of mongodb? – João Rocha da Silva Mar 05 '13 at 16:10
  • 2
    I just tried it on 2.2 and 1.8 and they both work for me – Sammaye Mar 05 '13 at 16:18
  • I just saw that I am using 2.2.3. I tried a different query, using the "graph" field, and it worked: > db.quads.find({graph:"u:http://example.org/people2"}) returns a single document. Now I am stumped. What is the difference between this query and all the other ones? NOTE: Stackoverflow removes the http:// at the beginning of the URL, but it is there. – João Rocha da Silva Mar 05 '13 at 16:19
  • Your example with the graph field omits the quotation marks around the field name, could that be the reason? (Should not be, but who knows …) – nutlike Mar 05 '13 at 16:46
  • @JoãoRochadaSilva I'm using 2.2.3 as well. – JohnnyHK Mar 05 '13 at 18:39
  • Does this field use an index? I have seen this once before when you index corruption, it is extremely rare but it can happen in certain scenarios. If this field uses an index try dropping the index – Sammaye Mar 05 '13 at 18:46
  • I've also queried with success here, v2.2.1. Most probably @Sammaye is right... – gustavohenke Mar 05 '13 at 19:48

1 Answers1

1

I was able to get the expected result using both approaches:

db.quads.find({"subject" : /.*Tim_Berners-Lee.*/}); and db.quads.find({"subject" : "u:http://dbpedia.org/resource/Tim_Berners-Lee"});

Maybe you are facing some shell windows encoding issue, please, list all docs as you said and be sure the output as input value of the find command. If possible try to connect from a different machine or try cygwin if you are using windows or try to connect from a linux machine.

Regards, Moacy

Moacy Barros
  • 1,869
  • 13
  • 9