Complex search with Mongodb

Asked

Viewed 76 times

1

I have a structure in mongoDB that has quantities of different items within an array called "items". To do the search, I am using the command below, which first transforms the content into a 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 don’t know how many items in each document, I would have to use a wildcard like this.items[*]. value, but that doesn’t work.

Does anyone know any solution, or has another idea for it?

1 answer

1

Solved using regex, posting the answer to interested:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.