V
V
Vlad Timofeev2015-01-19 23:41:34
Node.js
Vlad Timofeev, 2015-01-19 23:41:34

How to do a text search in MongoDB?

Good day, how to search for posts on mong + their pagination?
===============This is already solved, thanks smanioso ==================

Post.paginate({ 'access' : true, $text: {$search: req.body.call} },.... и так далее

Throws an error:
802a521458b44b0ab6046e249150b835.png
============================================= =================
But another problem appeared:
I set the indexes like this:
// tags это массив, остальное - типа Строка.
postSchema.index({ title: 'text', tags: 'text', text: 'text'});
// в роуте
Post.paginate({'access':true, '$text':{'$search':req.body.call}}, callback

But there is a post like this:
{
    "_id" : ObjectId("54beaa0a73ddc8e822708cd3"),
    "addtime" : "20.1.2015",
    "reviews" : 0,
    "readed" : true,
    "text" : "SomeTagSomeTagSomeTag",
    "num" : 2,
    "title" : "SomeTagSomeTag",
    "access" : true,
    "comments" : [],
    "author" : {
        "idNum" : 1
    },
    "tags" : [ 
        "SomeTag"
    ],
    "__v" : 0
}

And when I request a search with the SomeTag value (or in lowercase) - this post gives me.
But, when I write 'Some' or 'SomeTagSomeTag'(this is title) - empty array in response :((
How can I fix this?(((

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
smanioso, 2015-01-20
@PyTiMa

Apparently the problem is with indexes. Read here:
- habrahabr.ru/post/174457
- stackoverflow.com/questions/24257390/mongodb-text-...

V
Vlad Timofeev, 2015-01-20
@PyTiMa

Eh ... I set the indexes like this:

// tags это массив, остальное - типа Строка.
postSchema.index({ title: 'text', tags: 'text', text: 'text'});
// в роуте
Post.paginate({'access':true, '$text':{'$search':req.body.call}}, callback

But there is a post like this:
{
    "_id" : ObjectId("54beaa0a73ddc8e822708cd3"),
    "addtime" : "20.1.2015",
    "reviews" : 0,
    "readed" : true,
    "text" : "SomeTagSomeTagSomeTag",
    "num" : 2,
    "title" : "SomeTagSomeTag",
    "access" : true,
    "comments" : [],
    "author" : {
        "idNum" : 1
    },
    "tags" : [ 
        "SomeTag"
    ],
    "__v" : 0
}

And when I request a search with the SomeTag value (or in lowercase) - this post gives me.
But, when I write 'Some' or 'SomeTagSomeTag'(this is title) - empty array in response :((
How can I fix this?(((

S
stoitli, 2017-07-21
@stoitli

A memory leak is easily checked.
When 502 starts, just see how many processes are eating up memory.
Let's say the operating system's top command.
If go is eating up ALL available memory on the server, then yes, that's it.
If go eats a lot but still a lot of free memory in the operating system, then this is not it, not the memory leak that you suspect.

P
Papa, 2017-07-23
Stifflera @PapaStifflera

MySQL
https://ru.stackoverflow.com/questions/480160/%D0%...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question