Live/Dynamic query for MongoDB NodeJS - node.js

I'm making a NodeJS Express MongoDB app with the database of various books.
I have a list of books with information like Book Name, Author name, ISBN and so on.
View of the list here
I want to create a query function such that the page finds for relevant fields as I type along in the search text field.
Any suggestions how to implement it?

If you want to make text queries you can use the $text index on mongodb, and index the fields you need. this will allow you to search the text on all indexed fields.
you can read more about that here: https://docs.mongodb.com/manual/reference/operator/query/text/

Related

Full text search with different types besides String in MongoDB

I want to use full text search in MongoDB, and I know the solution of using text indexes (https://docs.mongodb.com/manual/core/index-text/). But, this solution is meant for searching on String type fields only.
How can I perform full text search on other types as well? Suppose I have a collection with documents in which I have fields from a variety of types like String, Number etc.
What can I do?
P.S: I use MongoDB native driver for Nodejs.
Wildcard Indexing
there can be scenarios where you want any text content in your documents to be searchable. Maybe this will help you.
db.collection.createIndex({"$**":"text"})

Id like to search cloudant by words and a range of timestamped dates via node-red

My cloudant database was created with the following: msg.payload via tweetnode to cloudant
{
"timestamp" : msg.tweet.timestamp_ms,
"tweet" : msg.tweet.text,
"sentiment" : msg.sentiment.score
}
I would like to search the tweets by word and a range of dates. Then save the results by tagging the tweets found back to cloudant via node-red.
This seems like a routine thing people do. I have not found any flows that do this. Any help is appreciated
Your index look right. Maybe the 404 was caused by the white spaces you have around the colon. Here a quick example: https://gist.github.com/lgfa29/d965e66bf1ffa0fff7ab26f314ea98de
You can copy this JSON document, click on the three dashes in the top right of the Node-RED editor and select Import > Clipboard. Then just paste the JSON content there and drop the nodes somewhere. You will also need to update the Cloudant node to point to your database and search index.
To query using search indexes you can use the Lucene query syntax, so to search for a range you would do something like timestamp:[1551464030329 TO 1551465568517]
Here is a sample I deployed: https://node-red-pet-dev.mybluemix.net/search?from=0&to=1651464030328&tweet=zebra* (sorry, my tweets are not very imaginative)

querieng document which doesn't have a given field or is empty string in Solr

I am doing a query with solr where I need to find documents without a given field say 'name' and I am trying following part;
$q=+status:active -name:["" TO *]'
But it sends both all the documents with and without that field.
Can anyone help me figure this out?
the field name is a normal String type and is indexed.
I am using nodejs. Can anyone help me with this
According to docs:
-field:[* TO *] finds all documents without a value for field
Update
I tried it but it sends even the ones with the field non empty
Then my wild quess is that you are using search query q instead of using filter query fq. Since you are using multiple statements in query I assume that q does some extra magic to get the most relevant documents for you, which can lead to returning some non-wanted results.
If you want to get the strict set of results you should use filter query fq instead, see docs.

what's the best way to bind a mongodb doc to a node.js html page

In past with my PHP / Rails - MYSQL apps I've used the unique ID of a table record to keep track of a record in an html file.
So I'd keep track of how to delete a record shown like this (15 being the ID of the record):
Delete this record
So now I'm using MongoDB. I've tried the same method but the objectID ._id attribute seems to be a loooong byte string that I can't use conveniently.
What's the most sensible way of binding a link in the view to a record (for deletion, or other purposes or whatever)?
If the answer is to create a new id that's unique for each document in the collection, then what's the best way to generate those unique id's?
Thank you.
You could use a counter instead of the ObjectID
But this could create a problem when inserting a new document after you deleted a previous one.
See this blog post for more detail info on Sequential unique identifiers with Node.js and MongoDB.
Or you could use the timestamp part of the ObjectID:
objectId.getTimestamp().toString()
See the node objectid docs

Implement Search Everything using Solr

How the search everything kind of application is indexing & keeping track of data into its search indexes.
Recently I have been working on Apache Solr which is producing amazing results for a search. But it was for one particular products catalog section that is being searched. As Solr is a stores it's data document, we indexed searchable fields as document in solr. I'm not sure how it can be used to build a search everything kind of search? And how should I index data into Solr?
By search everything I mean, to search into different module for information like Customers, Services, Accounts, Orders, Catalog, Support Ticket, etc. So search return results which is combined as a result from a single search form and user don't need to go into different forms for search that module?
Do I need to build different indexes for each such data models or store them into solr as single document? What is the best strategy to implement this.
You can store all that data in a single index with each document having an extra field that stores its type (Customer, Order, etc.). For the within-module search, just restrict the search query to documents of that type. For the Search All functionality, use copyField to copy all the relevant fields in each document type into one big field, and search with the document type field unconstrained.

Resources