Discussion:
Using $regex inside an $or: error
Alessio Dione
2013-04-17 16:16:42 UTC
Permalink
Hi there,
I tried googling and searching the group but couldn't find anything on this
specific case,
basically I need to look up using a regex in field A OR field B so I wrote
the equivalent of:

{
cid: 'xxxxxxx',
'$or': [
{ title: {'$regex': 'aaaa', '$options': 'i'} },
{ members: { '$regex': 'aaaa', '$options': 'i'} }
],
refids: {
'$in': [
"5167cb7dd6d68b8928000001",
"5167cf6356e26a2a2b000001"
]
}
}

However I'm getting this error from mongoosejs:
ERR: [Error: Can't use $options with Array.]

While the same works in the mongodb command line (converting the object ids
to proper object
rather than strings).

Am I understanding correctly that this is a mongoosejs limitation? How to
workaround it?
I'm using mongoose 3.6.5 with nodejs 0.10.4 on ubuntu linux.

Thanks,
Alessio
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Aaron Heckmann
2013-04-17 18:27:34 UTC
Permalink
I'm having trouble reproducing this. Can you post your code?
Post by Alessio Dione
Hi there,
I tried googling and searching the group but couldn't find anything on
this specific case,
{
cid: 'xxxxxxx',
'$or': [
{ title: {'$regex': 'aaaa', '$options': 'i'} },
{ members: { '$regex': 'aaaa', '$options': 'i'} }
],
refids: {
'$in': [
"5167cb7dd6d68b8928000001",
"5167cf6356e26a2a2b000001"
]
}
}
ERR: [Error: Can't use $options with Array.]
While the same works in the mongodb command line (converting the object
ids to proper object
rather than strings).
Am I understanding correctly that this is a mongoosejs limitation? How to
workaround it?
I'm using mongoose 3.6.5 with nodejs 0.10.4 on ubuntu linux.
Thanks,
Alessio
--
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
For more options, visit https://groups.google.com/groups/opt_out.
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Alessio Dione
2013-04-18 12:24:01 UTC
Permalink
So I started taking away pieces of code to isolate the problem, it turns
out the array the error message is complaining about
it's the field I'm running the regex against, basically this pieace of
query:

{ members: { '$regex': 'aaaa', '$options': 'i'} }

Where members is an array of strings.
I need to use the verbose version, e.g. filter['fieldName'] = { $regex:
criteria.searchKey, $options: 'i' };
rather than the concise one, e.g. filter['fieldName'] = { $regex:
/criteria.searchKey/i };
because the searchKey I'm using to build the regex it's a runtime value and
can't write that inline (or dunno how to do it....)

Is this clearer? Hope I can find sometime to prepare a testcase later...
thanks.
Post by Aaron Heckmann
I'm having trouble reproducing this. Can you post your code?
Post by Alessio Dione
Hi there,
I tried googling and searching the group but couldn't find anything on
this specific case,
basically I need to look up using a regex in field A OR field B so I
{
cid: 'xxxxxxx',
'$or': [
{ title: {'$regex': 'aaaa', '$options': 'i'} },
{ members: { '$regex': 'aaaa', '$options': 'i'} }
],
refids: {
'$in': [
"5167cb7dd6d68b8928000001",
"5167cf6356e26a2a2b000001"
]
}
}
ERR: [Error: Can't use $options with Array.]
While the same works in the mongodb command line (converting the object
ids to proper object
rather than strings).
Am I understanding correctly that this is a mongoosejs limitation? How to
workaround it?
I'm using mongoose 3.6.5 with nodejs 0.10.4 on ubuntu linux.
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Alessio Dione
2013-04-19 09:16:59 UTC
Permalink
Hi Aaron,
Here's a piece of code to reproduce the problem:

var util = require('util');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;


var sampleSchema = new Schema({
title: {type: String, default: ""}
, desc: {type: String, default: ""}
, membernames: [String]
});

var SampleModel = mongoose.model('Sample', sampleSchema);


//connect to single instance
mongoose.connect("mongodb://localhost/test", {server: { auto_reconnect:
true }}, function(err) {
if (err) console.log("something went wrong");
});


//connection's working
mongoose.connection.on('open', function () {

var a = new SampleModel({ title: "sample title", desc: "sample desc",
membernames: ["alfa", "beta", "gamma"] });
a.save( function (err, s) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {

SampleModel.find( { membernames: { $regex: /a/, $options: "i"
}}, null, null, function(err, f) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
console.log(f._id);
}
});
}
});
});


The console output is:

/usr/bin/node test/temp-unit/MongooseRegex.js
something went wrong
[Error: Can't use $options with Array.]
db.samples.findOne()
{
"_id" : ObjectId("517108f40ad58e7c52000001"),
"membernames" : [
"alfa",
"beta",
"gamma"
],
"desc" : "sample desc",
"title" : "sample title",
"__v" : 0
}
db.samples.find({membernames: {$regex: /a/, $options: 'i'}}).count()
5



As I pointed out yesterday, the problem is with the field type declared in
the schema: an array of Strings
if the fied was e.g. a simple string, then no error is thrown from mongoose.
--
Alessio
I'm having trouble reproducing this. Can you post your code?
Post by Alessio Dione
Hi there,
I tried googling and searching the group but couldn't find anything on
this specific case,
basically I need to look up using a regex in field A OR field B so I
{
cid: 'xxxxxxx',
'$or': [
{ title: {'$regex': 'aaaa', '$options': 'i'} },
{ members: { '$regex': 'aaaa', '$options': 'i'} }
],
refids: {
'$in': [
"5167cb7dd6d68b8928000001",
"5167cf6356e26a2a2b000001"
]
}
}
ERR: [Error: Can't use $options with Array.]
While the same works in the mongodb command line (converting the object
ids to proper object
rather than strings).
Am I understanding correctly that this is a mongoosejs limitation? How to
workaround it?
I'm using mongoose 3.6.5 with nodejs 0.10.4 on ubuntu linux.
Thanks,
Alessio
--
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
For more options, visit https://groups.google.com/groups/opt_out.
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Alessio Dione
2013-04-24 10:20:11 UTC
Permalink
Hi there,
Any feedback on this? Should I open a ticket?
Thanks.
Post by Alessio Dione
Hi Aaron,
var util = require('util');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var sampleSchema = new Schema({
title: {type: String, default: ""}
, desc: {type: String, default: ""}
, membernames: [String]
});
var SampleModel = mongoose.model('Sample', sampleSchema);
//connect to single instance
true }}, function(err) {
if (err) console.log("something went wrong");
});
//connection's working
mongoose.connection.on('open', function () {
var a = new SampleModel({ title: "sample title", desc: "sample desc",
membernames: ["alfa", "beta", "gamma"] });
a.save( function (err, s) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
SampleModel.find( { membernames: { $regex: /a/, $options: "i"
}}, null, null, function(err, f) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
console.log(f._id);
}
});
}
});
});
/usr/bin/node test/temp-unit/MongooseRegex.js
something went wrong
[Error: Can't use $options with Array.]
db.samples.findOne()
{
"_id" : ObjectId("517108f40ad58e7c52000001"),
"membernames" : [
"alfa",
"beta",
"gamma"
],
"desc" : "sample desc",
"title" : "sample title",
"__v" : 0
}
db.samples.find({membernames: {$regex: /a/, $options: 'i'}}).count()
5
As I pointed out yesterday, the problem is with the field type declared in
the schema: an array of Strings
if the fied was e.g. a simple string, then no error is thrown from mongoose.
--
Alessio
I'm having trouble reproducing this. Can you post your code?
Post by Alessio Dione
Hi there,
I tried googling and searching the group but couldn't find anything on
this specific case,
basically I need to look up using a regex in field A OR field B so I
{
cid: 'xxxxxxx',
'$or': [
{ title: {'$regex': 'aaaa', '$options': 'i'} },
{ members: { '$regex': 'aaaa', '$options': 'i'} }
],
refids: {
'$in': [
"5167cb7dd6d68b8928000001",
"5167cf6356e26a2a2b000001"
]
}
}
ERR: [Error: Can't use $options with Array.]
While the same works in the mongodb command line (converting the object
ids to proper object
rather than strings).
Am I understanding correctly that this is a mongoosejs limitation? How
to workaround it?
I'm using mongoose 3.6.5 with nodejs 0.10.4 on ubuntu linux.
Thanks,
Alessio
--
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
For more options, visit https://groups.google.com/groups/opt_out.
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Aaron Heckmann
2013-04-25 22:05:33 UTC
Permalink
Yes please. Taking a look now. Thanks for the great test case.
Post by Alessio Dione
Hi there,
Any feedback on this? Should I open a ticket?
Thanks.
Post by Alessio Dione
Hi Aaron,
var util = require('util');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var sampleSchema = new Schema({
title: {type: String, default: ""}
, desc: {type: String, default: ""}
, membernames: [String]
});
var SampleModel = mongoose.model('Sample', sampleSchema);
//connect to single instance
mongoose.connect("mongodb://**localhost/test", {server: {
auto_reconnect: true }}, function(err) {
if (err) console.log("something went wrong");
});
//connection's working
mongoose.connection.on('open', function () {
var a = new SampleModel({ title: "sample title", desc: "sample desc",
membernames: ["alfa", "beta", "gamma"] });
a.save( function (err, s) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
SampleModel.find( { membernames: { $regex: /a/, $options: "i"
}}, null, null, function(err, f) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
console.log(f._id);
}
});
}
});
});
/usr/bin/node test/temp-unit/MongooseRegex.**js
something went wrong
[Error: Can't use $options with Array.]
db.samples.findOne()
{
"_id" : ObjectId("**517108f40ad58e7c52000001"),
"membernames" : [
"alfa",
"beta",
"gamma"
],
"desc" : "sample desc",
"title" : "sample title",
"__v" : 0
}
db.samples.find({membernames: {$regex: /a/, $options: 'i'}}).count()
5
As I pointed out yesterday, the problem is with the field type declared
in the schema: an array of Strings
if the fied was e.g. a simple string, then no error is thrown from mongoose.
--
Alessio
I'm having trouble reproducing this. Can you post your code?
Post by Alessio Dione
Hi there,
I tried googling and searching the group but couldn't find anything on
this specific case,
basically I need to look up using a regex in field A OR field B so I
{
cid: 'xxxxxxx',
'$or': [
{ title: {'$regex': 'aaaa', '$options': 'i'} },
{ members: { '$regex': 'aaaa', '$options': 'i'} }
],
refids: {
'$in': [
"5167cb7dd6d68b8928000001",
"5167cf6356e26a2a2b000001"
]
}
}
ERR: [Error: Can't use $options with Array.]
While the same works in the mongodb command line (converting the object
ids to proper object
rather than strings).
Am I understanding correctly that this is a mongoosejs limitation? How
to workaround it?
I'm using mongoose 3.6.5 with nodejs 0.10.4 on ubuntu linux.
Thanks,
Alessio
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/**mongoose<http://github.com/learnboost/mongoose>
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/**questions/tagged/mongoose<http://stackoverflow.com/questions/tagged/mongoose>
Google Groups - https://groups.google.com/**forum/?fromgroups#!forum/**
mongoose-orm<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
For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
.
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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
For more options, visit https://groups.google.com/groups/opt_out.
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Aaron Heckmann
2013-04-25 22:18:20 UTC
Permalink
Ticket: https://github.com/LearnBoost/mongoose/issues/1462
Post by Aaron Heckmann
Yes please. Taking a look now. Thanks for the great test case.
Post by Alessio Dione
Hi there,
Any feedback on this? Should I open a ticket?
Thanks.
Post by Alessio Dione
Hi Aaron,
var util = require('util');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var sampleSchema = new Schema({
title: {type: String, default: ""}
, desc: {type: String, default: ""}
, membernames: [String]
});
var SampleModel = mongoose.model('Sample', sampleSchema);
//connect to single instance
mongoose.connect("mongodb://**localhost/test", {server: {
auto_reconnect: true }}, function(err) {
if (err) console.log("something went wrong");
});
//connection's working
mongoose.connection.on('open', function () {
var a = new SampleModel({ title: "sample title", desc: "sample
desc", membernames: ["alfa", "beta", "gamma"] });
a.save( function (err, s) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
"i" }}, null, null, function(err, f) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
console.log(f._id);
}
});
}
});
});
/usr/bin/node test/temp-unit/MongooseRegex.**js
something went wrong
[Error: Can't use $options with Array.]
db.samples.findOne()
{
"_id" : ObjectId("**517108f40ad58e7c52000001"),
"membernames" : [
"alfa",
"beta",
"gamma"
],
"desc" : "sample desc",
"title" : "sample title",
"__v" : 0
}
db.samples.find({membernames: {$regex: /a/, $options: 'i'}}).count()
5
As I pointed out yesterday, the problem is with the field type declared
in the schema: an array of Strings
if the fied was e.g. a simple string, then no error is thrown from mongoose.
--
Alessio
I'm having trouble reproducing this. Can you post your code?
Post by Alessio Dione
Hi there,
I tried googling and searching the group but couldn't find anything on
this specific case,
basically I need to look up using a regex in field A OR field B so I
{
cid: 'xxxxxxx',
'$or': [
{ title: {'$regex': 'aaaa', '$options': 'i'} },
{ members: { '$regex': 'aaaa', '$options': 'i'} }
],
refids: {
'$in': [
"5167cb7dd6d68b8928000001",
"5167cf6356e26a2a2b000001"
]
}
}
ERR: [Error: Can't use $options with Array.]
While the same works in the mongodb command line (converting the
object ids to proper object
rather than strings).
Am I understanding correctly that this is a mongoosejs limitation? How
to workaround it?
I'm using mongoose 3.6.5 with nodejs 0.10.4 on ubuntu linux.
Thanks,
Alessio
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/**mongoose<http://github.com/learnboost/mongoose>
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/**questions/tagged/mongoose<http://stackoverflow.com/questions/tagged/mongoose>
Google Groups - https://groups.google.com/**forum/?fromgroups#!forum/*
*mongoose-orm<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
For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
.
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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
For more options, visit https://groups.google.com/groups/opt_out.
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Aaron Heckmann
2013-04-25 22:21:55 UTC
Permalink
For now you can patch manually with:

mongoose.Schema.Types.Array.prototype.$conditionalHandlers.$options =
String


Or just pass a RegExp:

SampleModel.find({ membernames: /a/i }, callback)
Post by Aaron Heckmann
Ticket: https://github.com/LearnBoost/mongoose/issues/1462
Post by Aaron Heckmann
Yes please. Taking a look now. Thanks for the great test case.
Post by Alessio Dione
Hi there,
Any feedback on this? Should I open a ticket?
Thanks.
Post by Alessio Dione
Hi Aaron,
var util = require('util');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var sampleSchema = new Schema({
title: {type: String, default: ""}
, desc: {type: String, default: ""}
, membernames: [String]
});
var SampleModel = mongoose.model('Sample', sampleSchema);
//connect to single instance
mongoose.connect("mongodb://**localhost/test", {server: {
auto_reconnect: true }}, function(err) {
if (err) console.log("something went wrong");
});
//connection's working
mongoose.connection.on('open', function () {
var a = new SampleModel({ title: "sample title", desc: "sample
desc", membernames: ["alfa", "beta", "gamma"] });
a.save( function (err, s) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
"i" }}, null, null, function(err, f) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
console.log(f._id);
}
});
}
});
});
/usr/bin/node test/temp-unit/MongooseRegex.**js
something went wrong
[Error: Can't use $options with Array.]
db.samples.findOne()
{
"_id" : ObjectId("**517108f40ad58e7c52000001"),
"membernames" : [
"alfa",
"beta",
"gamma"
],
"desc" : "sample desc",
"title" : "sample title",
"__v" : 0
}
db.samples.find({membernames: {$regex: /a/, $options: 'i'}}).count()
5
As I pointed out yesterday, the problem is with the field type declared
in the schema: an array of Strings
if the fied was e.g. a simple string, then no error is thrown from mongoose.
--
Alessio
I'm having trouble reproducing this. Can you post your code?
Post by Alessio Dione
Hi there,
I tried googling and searching the group but couldn't find anything
on this specific case,
basically I need to look up using a regex in field A OR field B so I
{
cid: 'xxxxxxx',
'$or': [
{ title: {'$regex': 'aaaa', '$options': 'i'} },
{ members: { '$regex': 'aaaa', '$options': 'i'} }
],
refids: {
'$in': [
"5167cb7dd6d68b8928000001",
"5167cf6356e26a2a2b000001"
]
}
}
ERR: [Error: Can't use $options with Array.]
While the same works in the mongodb command line (converting the
object ids to proper object
rather than strings).
Am I understanding correctly that this is a mongoosejs limitation?
How to workaround it?
I'm using mongoose 3.6.5 with nodejs 0.10.4 on ubuntu linux.
Thanks,
Alessio
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/**mongoose<http://github.com/learnboost/mongoose>
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/**questions/tagged/mongoose<http://stackoverflow.com/questions/tagged/mongoose>
Google Groups - https://groups.google.com/**forum/?fromgroups#!forum/
**mongoose-orm<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,
For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
.
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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
For more options, visit https://groups.google.com/groups/opt_out.
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Alessio Dione
2013-05-03 09:29:48 UTC
Permalink
Thanks,
I patched it manually first and then yesterday upgraded to release 3.6.9,
both work perfectly.
Post by Aaron Heckmann
mongoose.Schema.Types.Array.prototype.$conditionalHandlers.$options =
String
SampleModel.find({ membernames: /a/i }, callback)
Post by Aaron Heckmann
Ticket: https://github.com/LearnBoost/mongoose/issues/1462
Post by Aaron Heckmann
Yes please. Taking a look now. Thanks for the great test case.
Post by Alessio Dione
Hi there,
Any feedback on this? Should I open a ticket?
Thanks.
Post by Alessio Dione
Hi Aaron,
var util = require('util');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var sampleSchema = new Schema({
title: {type: String, default: ""}
, desc: {type: String, default: ""}
, membernames: [String]
});
var SampleModel = mongoose.model('Sample', sampleSchema);
//connect to single instance
mongoose.connect("mongodb://**localhost/test", {server: {
auto_reconnect: true }}, function(err) {
if (err) console.log("something went wrong");
});
//connection's working
mongoose.connection.on('open', function () {
var a = new SampleModel({ title: "sample title", desc: "sample
desc", membernames: ["alfa", "beta", "gamma"] });
a.save( function (err, s) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
"i" }}, null, null, function(err, f) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
console.log(f._id);
}
});
}
});
});
/usr/bin/node test/temp-unit/MongooseRegex.**js
something went wrong
[Error: Can't use $options with Array.]
db.samples.findOne()
{
"_id" : ObjectId("**517108f40ad58e7c52000001"),
"membernames" : [
"alfa",
"beta",
"gamma"
],
"desc" : "sample desc",
"title" : "sample title",
"__v" : 0
}
db.samples.find({membernames: {$regex: /a/, $options: 'i'}}).count()
5
As I pointed out yesterday, the problem is with the field type
declared in the schema: an array of Strings
if the fied was e.g. a simple string, then no error is thrown from mongoose.
--
Alessio
I'm having trouble reproducing this. Can you post your code?
Post by Alessio Dione
Hi there,
I tried googling and searching the group but couldn't find anything
on this specific case,
basically I need to look up using a regex in field A OR field B so I
{
cid: 'xxxxxxx',
'$or': [
{ title: {'$regex': 'aaaa', '$options': 'i'} },
{ members: { '$regex': 'aaaa', '$options': 'i'} }
],
refids: {
'$in': [
"5167cb7dd6d68b8928000001",
"5167cf6356e26a2a2b000001"
]
}
}
ERR: [Error: Can't use $options with Array.]
While the same works in the mongodb command line (converting the
object ids to proper object
rather than strings).
Am I understanding correctly that this is a mongoosejs limitation?
How to workaround it?
I'm using mongoose 3.6.5 with nodejs 0.10.4 on ubuntu linux.
Thanks,
Alessio
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/**mongoose<http://github.com/learnboost/mongoose>
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/**questions/tagged/mongoose<http://stackoverflow.com/questions/tagged/mongoose>
Google Groups - https://groups.google.com/**
forum/?fromgroups#!forum/**mongoose-orm<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,
For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
.
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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
For more options, visit https://groups.google.com/groups/opt_out.
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Aaron Heckmann
2013-05-03 14:29:00 UTC
Permalink
Excellent
Post by Alessio Dione
Thanks,
I patched it manually first and then yesterday upgraded to release 3.6.9,
both work perfectly.
mongoose.Schema.Types.Array.**prototype.$**conditionalHandlers.$options
= String
SampleModel.find({ membernames: /a/i }, callback)
Ticket: https://github.com/**LearnBoost/mongoose/issues/**1462<https://github.com/LearnBoost/mongoose/issues/1462>
Post by Aaron Heckmann
Yes please. Taking a look now. Thanks for the great test case.
Hi there,
Any feedback on this? Should I open a ticket?
Thanks.
Hi Aaron,
var util = require('util');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var sampleSchema = new Schema({
title: {type: String, default: ""}
, desc: {type: String, default: ""}
, membernames: [String]
});
var SampleModel = mongoose.model('Sample', sampleSchema);
//connect to single instance
mongoose.connect("mongodb://**lo**calhost/test", {server: {
auto_reconnect: true }}, function(err) {
if (err) console.log("something went wrong");
});
//connection's working
mongoose.connection.on('open', function () {
var a = new SampleModel({ title: "sample title", desc: "sample
desc", membernames: ["alfa", "beta", "gamma"] });
a.save( function (err, s) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
"i" }}, null, null, function(err, f) {
if (err) {
console.log("something went wrong");
console.log(util.inspect(err, false, null, false));
} else {
console.log(f._id);
}
});
}
});
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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
For more options, visit https://groups.google.com/groups/opt_out.
--
Aaron
@aaronheckmann <https://twitter.com/#!/aaronheckmann>
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Loading...