2

I have a document containing a list of keywords which I want to search on, however Mongo only ever returns a single result even though there are many documents which contain the same keyword.

The documents look something like this:

{
    _Id: 51192567f5e65101d471c46b
    Name: "Cat",
    KeyWords: ["cat", "animal", "small"]
}

I am searching the database in the mongo shell using the following:

db.Resources.find({"KeyWords":"cat"})

I wanted to get back all documents where the KeyWords array contains cat (there are many), however I just get one document.

2
  • The schema in my example isn't the actual schema I'm working with, if I create a simple schema as above the search works as expected; there must be something in my full schema that's not quite right Commented Feb 12, 2013 at 10:58
  • 1
    I know it might sound obvious but do all documents in the collection have exactly the same structure? Commented Feb 12, 2013 at 11:19

2 Answers 2

1

I have just checked in my local DB, so please review your structure MongoDB

Sign up to request clarification or add additional context in comments.

Comments

0

Thanks for the replies; after much hunting, it turns out there was a piece of code in the program I'm using to load the data that only stores a single occurrence of any keyword, so although all documents appear to have lots of keywords, each keyword will only appear in a single document!! I was looking at the original data which had the keywords repeated between documents before the program stripped them out.

Data load failure!!!

Comments

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.