I have a already built old project on nodejs where I am using MongoDb to store data. Mongodb version is 2.4
The problem is I am running a text-search on a collection but it's never return anything which means console.log(arguments); never get print anything
It's to inform you guys that I am able to run db.socialposts.runCommand( "text", { search: "accessories",limit: 1 } )
on mongo terminal and getting results very fast
var options, search;
options = {
limit: 1
};
search = 'accessories';
console.log(search);
SocialPost.textSearch(search, options, function(err, out) {
console.log(arguments);
return true;
});
It's Schema is var schema;
schema = new mongoose.Schema({
entity_id: {
type: mongoose.Schema.Types.ObjectId,
required: true
},
social_id: {
type: String,
required: true
},
type: {
type: String,
required: true
},
app: {
type: String,
required: true
},
date: {
type: Date,
required: true
},
url: {
type: String,
required: true
},
post: {
type: String
},
title: {
type: String
},
image: {
type: String
},
video: {
type: String
},
hashtags: [String]
}, {
strict: 'throw'
});
And Index is
schema.index({
type: 1,
social_id: 1
});
schema.index({
type: 1,
entity_id: 1,
date: 1
});
schema.index({
title: 'text',
post: 'text'
});
I figured it out, it was a problem with mongoose connection, when I was running query it's status was connecting not connected; so, I changed it into following and it worked.
mongoose.connect('mongodb://localhost/test', function (err) {
ItemModel.textSearch('D', function (err, output) {
if (err)
console.log(err);
else
console.log(output);
mongoose.disconnect();
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.