【发布时间】:2013-12-28 10:43:09
【问题描述】:
从this 其他问题开始,我正在尝试根据用户的搜索输入收集包含关键字的条目。这是针对客户站点的,架构设置如下:
{
fid: Number, // unique id for client's internal purposes
email: String,
password: String, // hashed
name: {
first: String,
last: String
},
group: {
name: String,
description: String,
type: String
},
bio: {
short: String,
long: String
}
}
这是我的查询:
db.users.aggregate(
[{
$match: {
$or: [
{
'name.first': {
$regex: userInput,
$options: 'i'
}
},
{
'name.last': {
$regex: userInput,
$options: 'i'
}
},
{
'bio.short': {
$regex: userInput,
$options: 'i'
}
},
{
'bio.long': {
$regex: userInput,
$options: 'i'
}
}
]
},
{ $unwind: { '$name.first', '$name.last', '$bio.short', '$bio.long' } },
{
$match: {
$or: [
{
'name.first': {
$regex: userInput,
$options: 'i'
}
},
{
'name.last': {
$regex: userInput,
$options: 'i'
}
},
{
'bio.short': {
$regex: userInput,
$options: 'i'
}
},
{
'bio.long': {
$regex: userInput,
$options: 'i'
}
}
]
}
},
{ $group: { _id: '$fid', hitCount: { $sum: 1 } } },
{ $sort: { hitCount: -1 } }
}]
);
对于这种类型的查询,我不断收到意外的逗号或结束大括号。我似乎找不到我做错了什么(我已将我的 mongodb.conf 详细日志记录提高到 11)。我在哪里错了,我什至在正确的道路上吗?我想返回每个条目(对象?)以及除密码字段之外的所有信息,我该如何过滤掉它?
【问题讨论】: