This question already has answers here:
MongoDB Regular Expression Search - Starts with using javascript driver and NodeJS
(2 answers)
Closed 9 years ago.
i am trying to do the equivaleny in mongodb to sql LIKE search, but i cant have the results that i expected, i am follow this mappig sql to monog, but the result json is always empty. if i use a literal string works , but when pass a variable nothing happens
app.get("/questions/search/:query", function(req,res){
var querySearch = req.params.query;
//res.send(querySearch)
Question.find({title: /querySearch/ },function(err,docs){
if(err) res.json(err)
res.json(docs)
});
})
That find command will search for documents where the title contains the string "querySearch". This doesn't seem to be what you want to do. When you want to use find with a regular expression created at runtime, pass a RegExp object.
But please note that searching with regular expressions is slow. When you don't need all the features of regular expressions and only search for whole words, a text index might be the better choice.
Related
This question already has answers here:
Query Document Based on Regex in Firestore [duplicate]
(1 answer)
How to get a collection from firestore which is a Regular Expression?
(2 answers)
Closed 5 months ago.
I am trying with this code to search the product by name in the database but it gives those data which is the same as in a database. so give a better solution.
Code:
let response = await db
.collection("products")
.where("productName", ">=", req.body.searchText)
.where("productName", "<=", req.body.searchText + '\uf8ff')
.get();
Cloud Firestore doesn't provide a solution for full-text search. As you can see, you can use Elastic Search, Algolia or Typesense.
If you don't want such functionality, you can still use Firestore with a search that looks like this:
db.collection("products").orderBy("name")
.startAt(req.body.searchText)
.endAt(req.body.searchText + "\uf8ff");
If you're interested, for a better understanding, I recommend you read the following article:
How to filter Firestore data cheaper?
This question already has answers here:
How to query MongoDB with "like"
(45 answers)
Closed 8 months ago.
I worked with mongo before 3 years and now I'm back in Mongo and I don't know why today search ('%LIKE%' in SQL) is not working.
What I tried is as below.
{ "title": /${req.body.search}/i }
I searched a lot I all most tried all the way but don't know it seems not bed of roses for me.
Note: If I put static text then it's working but I need dynamic as per user search in my app.
Any help would be much appreciated.
MongoDB exposes as $regex operator to allow you search for items.
You could handle it like this:
// in your search handler
const searchTerm = new RegExp(req.body.search, "i")
Model.find({ "title": { $regex: searchTerm } })
This question already has answers here:
How can I see the SQL generated by Sequelize.js?
(4 answers)
Closed 6 years ago.
Good afternoon everyone. I am developing a node.js/express system using sequelize.js (postgresql).
My problem is: I need to store the raw queries generated by sequelize in a log history, but I can't find a function that returns the generated query. Does anyone know if sequelize provides a function that returns the generated SQL query, or if there's any other way to achieve this?
Your best bet is to use Sequelize's built-in logging functionality.
var sequelize = new Sequelize('db', 'username', 'pwd', {
// you can either write to console
logging: console.log
// or write your own custom logging function
logging: function (str) {
// do stuff with the sql str
}
});
This question already has answers here:
Node.js - Mongoose - Check if a collection exists
(4 answers)
Closed 8 years ago.
I am new to mongo Db and need to see if schema is already been created or not. I am using mongoose and node.js. If its not created i need to somehow run the creation script for once or else proceed with other stuff.
TIA
Assuming that by schema you mean that you want a check if the collection is already created in mongoDB, you should check this question here that explains the solution.
Quoting it:
Assuming you have a Mongoose Connection object named conn that's been opened using mongoose.createConnection, you can access the native mongo Db object via conn.db. From there you can call collectionNames which should provide what you're looking for:
conn.db.collectionNames(function (err, names) {
// names contains an array of objects that contain the collection names
});
You can also pass a collection name as a parameter to
collectionNames to filter the results to just what you're looking for.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Name already used by an existing object in VBA
I am using Oradynaset object to fetch the results from data base in VBA but the same object i.e OraDynaset does not work to create new table as i use the following query
strsql="create table abs.test as (select * from emp)"
Oradynaset=objDatabase.DBCreatedynaset(strsql,o&)
after running this query i get the error - ORA 009955:Object is used by an existing object.
can you please help me on this.
If you want to create/alter/drop databases and tables(ie. DDL), you should use the ExecuteSQL function of Objectdatabase object.
Oradynaset function of obdatabase objectis used for executing DML command in case of which it stores the fetched result that can be used later by looping through it.
Try by using object database object with sql query as parameter