Can't use $regex with String

1,536 views
Skip to first unread message

Branko Vukelić

unread,
Sep 6, 2011, 4:23:46 PM9/6/11
to mongoo...@googlegroups.com
I have a piece of code that goes something like this:

Place.find(
{'name': {$regex: '^' + query + '.*'}},
['name'],
function(err, places) {
....
}
);

I run this against mongoose 2.1.0 (updated a few seconds ago via npm),
and it fails with the following error message:

Error: Can't use $regex with String.

Does this mean it's not supported or that my code sucks (or both)?


--
Branko Vukelic
bra...@brankovukelic.com
bra...@herdhound.com

IDEA MACHINE
www.brankovukelic.com

Lead Developer
Herd Hound (tm) - Travel that doesn't bite
www.herdhound.com

Love coffee? You might love Loveffee, too.
loveffee.appspot.com

Aaron Heckmann

unread,
Sep 6, 2011, 4:27:42 PM9/6/11
to mongoo...@googlegroups.com
neither:

Place.find(
     {'name': new RegExp('^' + query + '.*') },


2011/9/6 Branko Vukelić <bra...@brankovukelic.com>
--
http://mongoosejs.com
http://github.com/learnboost/mongoose
You received this message because you are subscribed to the Google
Groups "Mongoose Node.JS ORM" group.
To post to this group, send email to mongoo...@googlegroups.com
To unsubscribe from this group, send email to
mongoose-orm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en



--
Aaron


Branko Vukelić

unread,
Sep 6, 2011, 4:31:16 PM9/6/11
to mongoo...@googlegroups.com
On 2011-09-06 16:27 -0400, Aaron Heckmann wrote:
> neither:
>
> Place.find(
> {'name': new RegExp('^' + query + '.*') },

Thanks!

Reply all
Reply to author
Forward
0 new messages