How to perform text search in mongoose without additional plugins

4,917 views
Skip to first unread message

Heisenberg

unread,
Aug 6, 2013, 8:58:31 AM8/6/13
to mongoo...@googlegroups.com
Hello!

I enabled textSearch in Mongodb and now want to use it via mongoose in my node js application.
My Schema looks like this:

var mongoose = require('mongoose');
mongoose
.connect('mongodb://localhost/products');

var productDB = mongoose.connection.db;

var Schema = mongoose.Schema;
var ProductSchema = new Schema({
        name
: {
            type
: String,
            required
: true,
            unique
: true,
       
},
        unitprice
: {
            type
: Number,
            required
: true
       
},
        description
: {
            type
: String,
            trim
: true,
       
},
        discontinued
: {
            type
: Boolean
       
},
        tags
: {
            type
: [String],
            index
: "text"
       
}
   
});

var Product = mongoose.model('Product', ProductSchema);

On the command line, I can use the text search like this:

db.products.runCommand("text", {search: "someSearchString"})

and it works fine.

Now I tried it in my app like described here, assuming that text defines the collection name, what seems quite strange to me...

productDB.command({
        text
: "products",
        search
: req.body.searchstring,
        limit
: 50
   
},...

but I don't get any results :(

Any suggestions?

Kind regards!




Aaron Heckmann

unread,
Aug 6, 2013, 9:55:37 AM8/6/13
to mongoo...@googlegroups.com
https://github.com/aheckmann/mongoose-text-search
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
Aaron



Heisenberg

unread,
Aug 6, 2013, 12:00:25 PM8/6/13
to mongoo...@googlegroups.com
Ok, this works for me, thanks...
Is it possible to work with wildcards so if I type "foo", "foobar" will match the query?
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
Aaron



Aaron Heckmann

unread,
Aug 6, 2013, 1:57:39 PM8/6/13
to mongoo...@googlegroups.com
As far as I know, mongodb text search doesn't support wildcards. You may want to read more about what is supported here: http://docs.mongodb.org/manual/core/text-search/

Regular indexes support wildcards through regexp queries. I've never tested using a text index. 


To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages