I’m trying to set up a few different saved organizational views on pages and am not having any luck with the custom MongoDB document queries.
I’m trying to create some views based on whether or not a page’s URL path matches the regex pattern, and based on the last edited date and of a page (also when the page was created).
I’ve tried different things, such as this post answer using the Content API Explorer but still no luck. This doesn’t seem like it should be too difficult to do, so I think something’s just not clicking for me. Could someone shared some examples of what I can do?
Here’s how to query by the last updated timestamp:
{ "lastUpdated": { $gt: 1610000000000 } }
The value in the lastUpdated field is the number of milliseconds elapsed since January 1, 1970. The $gt thingy is one of MongoDB’s comparison operators.
This is how to query by an URL prefix (using a regular expression):
Hi @armando , this was super helpful, thanks! Is there a way to do dynamic date math in the queries? (ex. I want to search for where lastUpdated is >30 days from today). I saw some examples online that use plain javascript, but it doesn’t like that’s supported in the custom query field.
Yeah, sadly, that’s not supported at the moment. We do some validation and sanitizing to the query, but at the moment we don’t add extra features, like a dynamic $currentDate expression you could use in your content queries.