Complex search with MongoDB

1

I have a structure in mongoDB that has different quantity of items inside an array called "items". To do the search, I am using the command below, which first transforms the content into string, because below this.items there is a different structure depending on the object:

db.getCollection('docs').find('JSON.stringify(this.items[0].value).toLowerCase().indexOf("tex")!=-1')

My problem is that since I do not know the amount of items in each document, I would have to use a wildcard type this.items [*]. value, but that does not work.

Does anyone know of a solution, or do you have any other ideas?

    
asked by anonymous 24.10.2016 / 13:02

1 answer

1

Solved using regex, posting the response to those interested:

db.docs.find({items: {$elemMatch: {value: /tex/i}}});
    
24.10.2016 / 17:31