node.js - 如何在 mongodb 中使用文档值长度进行搜索查询
问题描述
在我的收藏中,我有组,他们可以限制其中的成员。我想查询所有在搜索表单中给出的数字留下足够空间的组。我为我的 API 使用猫鼬和节点。
因此,当一个组中有 2 个成员时,限制为 3 并且用户搜索组中剩下的 2 个位置。该组不会显示,但会显示其他组。
我该如何查询这个?我已经找到了类似的东西,query.$expr = { $gt: [{ $strLenCP: "$members" }, params.searchValue /*2 in my example*/ ] };
但我真的不明白。
这是我的猫鼬模式:
let GroupSchema = new Schema({
name: {
type: String,
required: true
},
status: {
type: String,
required: true
},
game: {
type: Schema.Types.ObjectId,
ref: 'Games',
required: true
},
alias: {
type: String,
required: true,
unique: true
},
owner: {
type: Schema.Types.ObjectId,
ref: 'User'
},
range: Number,
image: String,
description: String,
members: [{
type: Schema.Types.ObjectId,
ref: 'User'
}],
updated: Date,
created: Date
});
解决方案
推荐阅读
- flutter - Flutter 冲洗条/小吃条样式
- javascript - 如何创建一个无限(在 x 轴上)可滚动的元素来重复它的内容
- python - 在 python 中使用 while 循环未获得所需的输出
- php - 从 SQL 数据库中选择存在具有用户 ID 的行,然后获取具有相似值的所有其他行
- r - 如何在 html/RMarkdown 中正确呈现表格,括号中为数字
- node.js - 404 使用路由器和不同的路由文件
- javascript - 如何将jquery更改为js
- javascript - SVG逐帧动画(
) - c# - Azure Blob 存储 DownloadToStreamAsync 在网络更改期间挂起
- reactjs - 使用 cookie 存储令牌