mongoose get elements that contain substring
Books.find( { "authors": { "$regex": "Alex", "$options": "i" } }, function(err,docs) { } );
Here is what the above code is Doing:
1. We’re using the find() method to search for all documents in the books collection.
2. We’re using the $regex operator to find all documents where the authors field contains the string “Alex”.
3. We’re using the $options operator to make the search case insensitive.