0

I have a mongo collection which has an array of arrays (bigrams from a NLP process) that I'd like to be able to search, so for example;

{
    "sentence" : "will most likely be",
    "biGrams" : [["will","most"], ["most","likely"], ["likely", "be"]
},
{
    "sentence" : "likely most people use stackoverflow",
    "biGrams" : [["likely","most"], ["most","people"], ["people", "use"], ["use", "stackoverflow"]
}

What I'd like to be able to do is search through the biGram sub-doucment for a certain instance of one of these bigrams, e.g. search for all sentences that contain the bigram ["most","likely"].

I've tried this;

find({'biGrams':{$elemMatch: {$elemMatch:{$in:['most','likely']}} }})

But this obviously finds all cases with the word 'most' or 'likely' are present. And the order is important, i.e. I don't want to find docs with ['likely','most'] in this example.

Thanks in advance, I'm stumped....

1
  • Ack, being dumb. Simple; find({'biGrams':["likely", "most"]}) Commented Dec 5, 2013 at 17:12

1 Answer 1

1

How about

find({"biGrams":["most","likely"]})

Searching on a particular field "unwinds" one level of arrays in that field, and searching for a particular array should be a binary match on that array.

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

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.