1

I know there is already a lot on this subject out there, but none of the questions do help me going on. I have a File-Upload-System via GridFS which generates documents like this:

    { "_id" : ObjectId( "4f3723607b5c0b8d01060000" ),
  "filename" : "7326_150970547928_746052928_2521002_2164327_n.jpg",
  "filetype" : "image/jpeg",
  "title" : "Indexed File 1",
  "author" : "chewbacca",
  "document" : "Rechnungen",
  "keywords" : { "0" : "Darth",
    "1" : "Vader",
    "2" : "Haut",
    "5" : "Putz",
    "6" : "Pushy" },
  "uploadDate" : Date( 1329013600519 ),
  "length" : 61423,
  "chunkSize" : 262144,
  "md5" : "c73cce0bb6f349007635751f9a1a7ddd" }

As you can see I have a field 'keywords' which is an array of keywords. I want to build a search-option to search this field comparable to a fulltext search. Therefor I indexed the field 'keywords' seperately.

db.fs.files.ensureIndex({ keywords : 1 })

Now the problem is, that this works sometimes. Or to say yesterday it worked on some files, but on some it won't find anything.

Assuming I did the Indexing like above, I would think that

> db.fs.files.find({keywords : "Vader"})

would give me the document printed above. Or am I missing something??

(My only explanation why this could be, is: it takes a lot of time to create indexes and it ain't ready yet, which is practically impossible right, or that there is some problem with the options 'background', 'dropDups', 'unique' etc...

I tried everything. I dropped the Indexes with;

> db.fs.files.dropIndexes()

And created them again. Always controlling via

> db.fs.files.getIndexes()

But no, I can't get any results...

I also tried to make the indexing via PHP just after I saved the file in the database. For that I use the following code:

    $gridFS->ensureIndex(array('keywords' => 1), array("unique" => true));

Or also without the unique option.


As I said sometimes this works and I can query the keywords, but sometimes I can't. Or some keywords are found, but those of other documents not. Could it be that indexes ain't made for every document equally???

Please somebody help me on that, I really don't get the issue here!

Thanks already.

1 Answer 1

3

I suggest you to use a true array in the keywords:

"keywords" : ["Darth", "Vader", "Haut", "Putz", "Pushy"],

So, the following is expected to work:

db.fs.files.ensureIndex({ keywords : 1 })
db.fs.files.find({keywords : "Vader"})
Sign up to request clarification or add additional context in comments.

2 Comments

What do you mean with 'true array'? In the meantime I went on trying, and again achieved something, that partially works. On some files I do get the results properly, on some I don't...
In JSON, { 0 : "Darth", 1 : "Vader"} is an object, not an Array; ["Darth", "Vader"] is a true array; you can check it thru instanceof Array. Please, give us the examples that don't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.