Help with custom query table filters

Hi there,

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?

Thanks,
Robbie

Hey @robbie, what do you want to be querying? We’re happy to test and provide some examples!

Hi @kara , that would be great! Here are a few things I’d like to query on:

  1. Pages with URL paths that match a specific regex pattern (ex. /video/footage/*)
  2. Pages that were last edited more than 1 month ago

Hopefully with the examples I’ll be able to create other variations that I’m looking for!

Thanks,
Robbie

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):

{
  "query": {
    "$elemMatch": {
      "property": "urlPath",
      "value": {
        "$regex": "^/video/footage"
      }
    }
  }
}

Keep in mind that the query field is an array of objects with a shape like:

{
  property: string,
  operator: string,
  value: string,
}
1 Like

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.