Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Mongodb v3 index search in Parse Server? #6781

Closed
codetycon opened this issue Jul 8, 2020 · 20 comments
Closed

How to use Mongodb v3 index search in Parse Server? #6781

codetycon opened this issue Jul 8, 2020 · 20 comments
Labels
type:docs Only change in the docs or README type:question Support or code-level question

Comments

@codetycon
Copy link

Hi All,

I am using Parse Server with Mlab. I have created a Multikey index from mlab dashboard. Now I wan to use search in Cloud Function of Parse Server, but I didn't found any option in Parse Server to run Query and order by on a specific field.

Anyone have idea how we can perform Search and other MOngo V3 queries in parse server?

Thanks

@mtrezza mtrezza added the type:question Support or code-level question label Jul 8, 2020
@mtrezza
Copy link
Member

mtrezza commented Jul 8, 2020

In the docs you can find examples:

// Sorts the results in ascending order by the score field
query.ascending("score");

// Sorts the results in descending order by the score field
query.descending("score");

MongoDB will automatically choose an appropriate index. You can find more infos regarding indexing in the docs.

@codetycon
Copy link
Author

In the docs you can find examples:

// Sorts the results in ascending order by the score field
query.ascending("score");

// Sorts the results in descending order by the score field
query.descending("score");

MongoDB will automatically choose an appropriate index. You can find more infos regarding indexing in the docs.

I already implemented this but this searching on only one column , I want to apply search on all columns like firstname, lastname and description and want to order by firstname. I have achieved this by OR query but this query taking long execution time on my 175K records.

ANy solution?

@mtrezza
Copy link
Member

mtrezza commented Jul 9, 2020

I want to apply search on all columns like firstname, lastname and description and want to order by firstname.

let query = new Parse.Query("_User");
query.equalTo("firstname", "John");
query.equalTo("lastname", "Doe");
query.equalTo("description", "example");
query.descending("firstname");

If this is not what you mean, please provide an example data set, your current code, the current multikey index, the expected results and the actual results. You may find it helpful to use the issue template for better overview.

@codetycon
Copy link
Author

codetycon commented Jul 9, 2020 via email

@mtrezza
Copy link
Member

mtrezza commented Jul 9, 2020

You would have to create a text index manually in the DB:

db.Artists.createIndex({
    firstname: "text",
    lastname: "text",
    description: "text"
})

Then do a text search as described in the docs:

let query = new Parse.Query("Artists");
query.fullText("firstname", "paint");
query.ascending("firstname");
let results = await query.find();

If a text index is a compound index, then the search will automatically cover all fields of the text index. This is expected behavior by MongoDB but not explicitly mentioned in the Parse Server docs.

It makes sense to add this to the docs, a PR would be very welcome.

@mtrezza mtrezza added type:docs Only change in the docs or README troubleshooting and removed type:question Support or code-level question labels Jul 9, 2020
@codetycon
Copy link
Author

codetycon commented Jul 9, 2020 via email

@codetycon
Copy link
Author

You would have to create a text index manually in the DB:

db.Artists.createIndex({
    firstname: "text",
    lastname: "text",
    description: "text"
})

Then do a text search as described in the docs:

let query = new Parse.Query("Artists");
query.fullText("firstname", "paint");
query.ascending("firstname");
let results = await query.find();

If a text index is a compound index, then the search will automatically cover all fields of the text index. This is expected behavior by MongoDB but not explicitly mentioned in the Parse Server docs.

It makes sense to add this to the docs, a PR would be very welcome.

I have applied this but the search does not returning all the match result in a sorting (firstname ascending) and also lot of search saying no records but we have an search string in the description field.

@mtrezza
Copy link
Member

mtrezza commented Jul 10, 2020

You can try to execute the query directly against MongoDB without using Parse and see if you get the expected results. If you also don't get the expected results from a direct query, then you may look at the data and index and maybe consult the MongoDB docs on how to get your expected results.

If you get the correct results from MongoDB but not from Parse, then we need to look at the details:

  • Parse query code
  • records in DB
  • index in DB
  • expected results
  • actual results
  • Parse Server log entries
  • MongoDB log entries (executed query)

@codetycon
Copy link
Author

It seems to be working, I think indexing was under processing..

@mtrezza
Copy link
Member

mtrezza commented Jul 12, 2020

Great, would you want to create a PR for the docs and add an example for compound text index? That could certainly help others.

@codetycon
Copy link
Author

Yes, that would be a great to have an detailed documentation, MongoDb have an well described documentation but this is missing in the Parse.

@mtrezza
Copy link
Member

mtrezza commented Jul 12, 2020

Do you want to add it to the docs?

@codetycon
Copy link
Author

Yes

@codetycon
Copy link
Author

Please also post the link of documentation in this ticket, so user who read this issue can find documentation directly.

@mtrezza
Copy link
Member

mtrezza commented Jul 12, 2020

You can link to the documentation after you have added it. Just to be clear, I was asking if you want to submit a pull request the change to the documentation yourself.

@codetycon
Copy link
Author

You mean I need to write a document for this? If yes then where?

@mtrezza
Copy link
Member

mtrezza commented Jul 12, 2020

You mean I need to write a document for this? If yes then where?

Yes, that would be very helpful. 🙂 It is quite easy, you can find some guides online how to make a pull request.

For example this guide if you use Github Desktop. Let me know if you need any help and I will guide you.

@codetycon
Copy link
Author

Thanks for the info, I will create doc for this and push to the repo.

@mtrezza
Copy link
Member

mtrezza commented Jul 25, 2020

Let me know if you need any help with how to contribute and open a PR 🙂

@mtrezza
Copy link
Member

mtrezza commented Jul 27, 2020

I'm closing this as it seems to be resolved. Feel free to comment if you have any questions and we can re-open this issue.

Docs issue in parse-community/docs#750

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:docs Only change in the docs or README type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

2 participants