我有mongodb中的Ebooks数据集合
{
"_id" : ObjectId("58b56fe19585b10cd42981d8"),
"cover_path" : "D:\\Ebooks\\uploads\\ebooks\\cover\\1488285665748-img1-700x400.jpg",
"path" : "D:\\Ebooks\\uploads\\ebooks\\pdf\\1488285665257-Webservices Natraz.pdf",
"description" : "ebook",
"title" : "book name",
"tag" : [
"Hindi",
"Other"
],
"__v" : NumberInt(0)
}
Run Code Online (Sandbox Code Playgroud)
现在我想搜索一些东西,如果关键字是一点点匹配,"title:"然后显示所有相关的书籍对象.
我的Mongoose架构是: -
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var EbookSchema = new Schema({
title: {type:String},
description: {type:String},
path: {type:String,required:true},
cover_path: {type:String,required:true},
tag: [{ type: String }]
});
module.exports = mongoose.model('Ebook', EbookSchema);
Run Code Online (Sandbox Code Playgroud)
我试试: -
app.get('/ebook?search=',function(req,res){
var search_key = req.param('search');
Ebook.find(title:'search',function(err, ebooks) {
if (err)
res.send(err);
res.json(ebooks);
}); …Run Code Online (Sandbox Code Playgroud) 如果您要在网站上向任何用户显示什么手机号码,但出于安全原因,您不会显示完整的手机号码,例如 9305070207,您只会显示 93*****207。尝试这个正则表达式 -:
var str="9305070207";
var str1="9305070207";
var formetNum = str.replace(/\d{8}$/,'')+str1.replace(/^\d{7}/,'*****');
document.write(formetNum);
Run Code Online (Sandbox Code Playgroud)
如果这个过程有更好的方法请告诉我。我提高我的知识