问题描述
我正在用Mlab在heroku上运行parse server(2.8.4)
.我试图基于单词匹配进行搜索,但是全文抛出错误,这是我的查询:
I am running parse server(2.8.4)
on heroku with Mlab. I a trying to search based on word match but the fullText throwing an error,here is my query:
var query1 = new Parse.Query("SearchTerms");
query1.fullText("searchString", "programmer");
它抛出以下错误:
ParseError {
2019-11-24T03:01:42.421284+00:00 app[web.1]: code: 1,
2019-11-24T03:01:42.421285+00:00 app[web.1]: message: {
2019-11-24T03:01:42.421286+00:00 app[web.1]: name: 'MongoError',
2019-11-24T03:01:42.421287+00:00 app[web.1]: message: 'text index required for $text query',
2019-11-24T03:01:42.421288+00:00 app[web.1]: ok: 0,
2019-11-24T03:01:42.421289+00:00 app[web.1]: errmsg: 'text index required for $text query',
2019-11-24T03:01:42.421290+00:00 app[web.1]: code: 27,
2019-11-24T03:01:42.421291+00:00 app[web.1]: codeName: 'IndexNotFound',
2019-11-24T03:01:42.421292+00:00 app[web.1]: operationTime: '6762703032942592018',
2019-11-24T03:01:42.421293+00:00 app[web.1]: '$clusterTime': { clusterTime: '6762703032942592018', signature: [Object] }
2019-11-24T03:01:42.421294+00:00 app[web.1]: }
2019-11-24T03:01:42.421295+00:00 app[web.1]: }
在网络上,我找到了以下解决方案:
On Web I found below solution:
db.collection.createIndex(
{
field1: "text",
field2: "text",
etc...
}
)
但是我不知道该代码放在哪里.
But I don't know where to place this code.
有什么办法可以与mlab
已按照@Suat的指南解决了索引问题
但是新问题到来了:我正在使用10或使用fullText
查询并收到此错误:
But new issue arrives:I am using 10 or query with fullText
and getting this error:
[31merror[39m: Error generating response. ParseError {
2019-11-25T08:46:46.632775+00:00 app[web.1]: code: 1,
2019-11-25T08:46:46.632776+00:00 app[web.1]: message: MongoError: Too many text expressions
2019-11-25T08:46:46.632778+00:00 app[web.1]: at queryCallback (/app/node_modules/mongodb-core/lib/cursor.js:247:25)
2019-11-25T08:46:46.632779+00:00 app[web.1]: at /app/node_modules/mongodb-core/lib/connection/pool.js:531:18
2019-11-25T08:46:46.632781+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:75:11) {
2019-11-25T08:46:46.632783+00:00 app[web.1]: name: 'MongoError',
2019-11-25T08:46:46.632784+00:00 app[web.1]: message: 'Too many text expressions',
2019-11-25T08:46:46.632785+00:00 app[web.1]: ok: 0,
2019-11-25T08:46:46.632787+00:00 app[web.1]: errmsg: 'Too many text expressions',
2019-11-25T08:46:46.632788+00:00 app[web.1]: code: 2,
2019-11-25T08:46:46.632789+00:00 app[web.1]: codeName: 'BadValue',
2019-11-25T08:46:46.632791+00:00 app[web.1]: operationTime: Timestamp { bsontype: 'Timestamp', low: 6, high_: 1574671603 },
2019-11-25T08:46:46.632792+00:00 app[web.1]: '$clusterTime': { clusterTime: [Timestamp], signature: [Object] },
2019-11-25T08:46:46.632793+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2019-11-25T08:46:46.632794+00:00 app[web.1]: }
推荐答案
您的问题主要是针对MongoDB和mLab的.
Your question is mostly MongoDB and mLab specificed.
- 打开您的mLab仪表板
- 选择部署
- 选择您的数据库
- 选择您的收藏
在收集详细信息页面上,页面顶部有文档,索引,统计信息,工具.
In collection detail page there are Documents, Indexes, Stats, Tools on top of page.
选择索引,然后单击添加索引"按钮,将出现一个弹出屏幕,您可以输入类似的索引
Choose Indexes and click to 'Add Index' button there will be a popup screen which you can enter indexes like that
{
"job": "text"
}
,然后单击在后台创建"按钮.几秒钟后,您的索引将被创建,现在您可以使用fullText函数了.
and then click 'Create In Background' button. After a few seconds your index will be created and now you can use your fullText function.
但是请记住
这篇关于fullText在带有Mlab的Parse Server中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!