gpt4 book ai didi

RethinkDB:​​如何按字符串字段的长度排序?

转载 作者:行者123 更新时间:2023-12-02 09:36:24 25 4
gpt4 key购买 nike

假设我有一个带有标题字段的文章表。我如何获得按标题长度排序的文章列表?

例如。文章:

{id: '101', title: 'A title', contents: 'Lots of text'}

我尝试过:

r.table('story').orderBy(function(doc){return r.row('title').length}).pluck('title')

但这是错误的。

最佳答案

您现在可以使用split("").count()作为解决方法

r.table("story").orderBy(function(doc) {
return doc("title").split("").count()
}).pluck("title")

参见https://github.com/rethinkdb/rethinkdb/issues/264跟踪 native 方法的进度以获取字符串的长度。

关于RethinkDB:​​如何按字符串字段的长度排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25681430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com