我尝试使用link这样的全文搜索功能
但是当我尝试localhost:3000/motel/full-search-test/h
时返回
没有结果
我使用mlab在线存储数据库,它可用于除此功能以外的所有功能。我怎么解决这个问题?
我的模特:
var mongoose = require("mongoose"); //
var Schema = mongoose.Schema; //
var motelSchema = new Schema({
_creator: { type: Schema.Types.ObjectId, ref: 'User' },
add: String,
address: String,
area: { type: Number, default: 0},
category: String,
city: String,
contact: String,
created_at: {required: true, type: Date, default: new Date()},
customer: String,
description: String,
district: String,
fields: { type: [String], index: true, text: true },
img: {type: [String]},
lng: String,
lat: String,
price: { type: String, default: "Thỏa thuận"},
rating: {type: Number, default: 4.75},
status: { type: Number, default: 0},
street: String,
title: { type: String, required: true },
ward: String
},{collection : 'motels'});
motelSchema.set('autoIndex', false); // prevent mlab autoindex
motelSchema.index({'$**': 'text'});
var motels = mongoose.model("motels", motelSchema);
module.exports = motels;
我的服务:
service.test = test;
module.exports = service;
function test(searchString) {
var deferred = Q.defer();
motels.find({$text: {$search: searchString}})
.skip(20)
.limit(10)
.exec(function(err, motels) {
if(err) {
deferred.reject(err);
}
deferred.resolve(motels);
});
return deferred.promise;
}