如何在Grails中对复杂的mongoDB查询进行分页



我有三个域类作者,评论和书籍:

class Author {
String name
static hasMany = [books: Book, comments: Comment]
}
class Book {
static belongsTo = [author: Author]
static hasMany = [comments: Comment]
}
class Comment {
static belongsTo = [book: Book, author: Author] 
}

我有以下mongoDB查询来查找所有具有给定作者评论的书籍。

Comment.findAllByAuthor(author1).collect {
        it.book
    }.unique().findAll { 
        it != null 
}

如何对此查询使用分页,即对所有书籍进行分页?

将条件查询与 Book 而不是注释一起使用:

def c = Book.createCriteria()
def PaginatedBookList = c.list(max: params.max, offset: params.offset) {
    and{
        eq('author',author1)
        isNotNull('comments')
    }
}

最新更新