How to get collections in path using pattern matching?

108 Views Asked by At
collections:
    posts: ->
        # @getCollection('documents').findAllLive({relativeDirPath: 'posts'}, [date: -1])
        @getCollection('documents').findAllLive({relativeDirPath: {'$in' : ['posts', /post\/[0-9]+/ ]}}, [date: -1])

In the main docpad.coffee, {relativeDirPath: {'$in' : ['posts']} is the standard thing to do.

However, {relativeDirPath: {'$in' : ['posts', /post\/[0-9]+/ ]} does not.

I am trying to get files that are in the following directory structure to be added to the posts collection:

/src/documents/posts/blah-blah.html
/src/documents/post/12345678/foo-bar-baz.html
/src/documents/post/62347878/woop-woop.html

... and using pattern matching in relativeDirPath seems to be the way to go. However, it does not match any of those files. How can I make this work?

1

There are 1 best solutions below

0
On

Based on the requirement, you don't need pattern matching. The group query key "$or" should work for you:

@getCollection('documents').findAllLive
    $or: [
            {
                relativeDirPath:
                    "$startsWith": "posts"
            }
            {
                relativeDirPath:
                    "$startsWith": "post"
            }
        ]
, [date: -1]