I have an object that looks like this:
let SentenceSchema = new mongoose.Schema({
sentence: { type: String, required: true },
language: { type: String, required: true },
tokens: [{ type: String }]
});
I have an array that looks like this
let words = ['i', 'love', 'you', 'me', 'cheese', 'and'];
I would like to find all objects where all of the tokens are present in this array. This is what i already tried:
Sentence.find({ tokens: { $all: words } });
Which only returns one result, i love you me and cheese, whereas i'd like it to return other results too, like i love you and you love me.
If i change the operator from $all to $in, then I get more results than intended because something like cheese is a food that i love would also be matched.
I simply want to return all sentences where all the tokens strings are present in the above words array. Is something like this possible?