MongoDB Text Search -


I think we limited the number of items scanned in mongodb text search using the method outlined in this document Can:

Let me write briefly. I have a collection of inventory documents:

  {_id: 1, dept: "tech", Description: "Lime green computer"} {_id: 2, dept: "tech", Details : "Red Piere"} {_id: 5, dept: "Wireless Red Mouse"} {_id: 3, dept: "Kitchen", Description: "green place"} {_id: 4, dept: "Kitchen", Description:  

Then I have created an index:

I can write this question and it works:

 

  db.inventory.ensureIndex ({dept: 1, description: "text"})  

db.inventory.find ({Department : "Kitchen", $ text: {$ search: "green"}})

Now, if I see this view I use the triangle, then I search in a specific department. My problem is, I want this feature, but I also want freedom of searching in all departments. But this query does not work: db.inventory.find ({$ text: {$ search: "green"}})

I used version 2.6.5 I am

The index you made is a compound, so there is no way to run db. .find ({$ text: {$ search: "green"}}) .

If you want to run both, then you must index the

  db.inventory.ensureIndex ({description: "text", dept: 1}) Can be changed  

but the first query will be more scanning.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -