Saloni Malhotra
1 min readAug 2, 2017

Search in mongoose in Hapi js

Well,Just for people who are lookin for the answer i was i did like this.Here is my post Schema

var Mongoose = require(‘mongoose’),
Schema = Mongoose.Schema;

var PostSchema = new Schema({
name:{type: String},
mobile_number: {type: String},
email: {type: String,},
address:{type: String },
project_title: { type: String},
cities:{type: String},
});

var post = Mongoose.model(‘post’, PostSchema, ‘post’);
module.exports = {
Post: post
};

Let us suppose I want to search on the basis of project_title so i have to use mongoose find query
Firstly, i was create an object .you can also pass directly into find query

var criteria = {
project_title = new RegExp(params.search, “i”)
}

search is the parameter i am passing from my routes and params is the argument in my function ……….

So the mongoose find query for searching

Models.post.Post.find(a,function(err,res){
if(err){
callback(err);
}else{
callback(res);
}
});

Hope,this will be beneficially for all of you………….if you have any query reagrding this article .please feel free to ask me……

Thank you :)

Have a nyc day !!

Saloni Malhotra

I write about web development, Answers questions on Quora. Solving people problems using code spells. Web developer, Writer, Thinker.