Does the $text mongoDB operator work?

The content API documentation says that MongoDB query operators can be used to filter content:

One of these is $text:

Source: https://docs.mongodb.com/manual/reference/operator/query/

When I try this in requests on the content API, I don’t see any change to the results returned. Is this operator supported?

hi @jballo - we don’t support expression operators, but we do support $regex, so one way people do text search of Builder content is by using like

{ $regex: /.*pattern.*/, $options: 'gi' }

another good solution is to use our Aloglia plugin to sync your content there and use Algolis for full text search

Thanks for the info, Steve, that’s really helpful!

Would it be possible for someone to update the documentation, so that it lists out which operators are supported and not? The way it stands now, it’s a difficult user experience, where it’s unclear what things I’m not implementing right vs are not supported, of the MongoDB operators.

As a side question - is there a way to do an OR condition in the Content API? Wondering about checking two fields for things, where I want the result to include records where either condition is met.

Absolutely will do. And yeah $or and $and is supported

?query={$or:[...]}

Just updated the Content API doc to list out what operators we support. Luckily it’s in Builder.io so only took me about 2 minutes to update and publish :slight_smile:

1 Like