Quantcast
Viewing all articles
Browse latest Browse all 48

Answer by kz_sergey for How to query MongoDB with "like"?

Use aggregation substring search (with index!!!):

db.collection.aggregate([{
        $project : {
            fieldExists : {
                $indexOfBytes : ['$field', 'string']
            }
        }
    }, {
        $match : {
            fieldExists : {
                $gt : -1
            }
        }
    }, {
        $limit : 5
    }
]);

Viewing all articles
Browse latest Browse all 48

Trending Articles