"Not like" query with c++ driver

208 views
Skip to first unread message

YAC

unread,
Jan 27, 2012, 10:45:07 AM1/27/12
to mongodb-user
Hello,

I'm now developping a MongoDB c++ interface for an existing
application. At the moment, this application worked with MaxDB and
PostgreSQL. As this is not a new project, I have to overwrite all
existing features and I can't just change the queries.

Now I have a problem with "Not Like" queries.

In fact, it is easy to do "like" queries with C++ driver as
following :
BSONObj test;
test =
BSON(std::string("$regex")<<mg<<std::string("$options")<<"i");
test = BSON("x"<<test);
It's easy to do a "not like" query with command shell also.

But I don't know how to do a "not like" query with C++ driver.
I tried :
test =
BSON(std::string("$regex")<<mg<<std::string("$options")<<"i");
test = BSON(std::string("$not")<<test);
test = BSON("x"<<test);
I got a error when executing the query. It seems that $not operator
and $regex operator do not work together.

Can you give me an idea please ? Many thanks.

Eliot Horowitz

unread,
Jan 27, 2012, 12:28:20 PM1/27/12
to mongod...@googlegroups.com
Can you try doing it this way?

BSONObjBuilder x;
x.appendRegex( "$not" , mg );
BSONObj test = BSON( "x" << x.obj() );

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>

YAC

unread,
Jan 27, 2012, 12:50:56 PM1/27/12
to mongodb-user
Thank you very much.
It works with x.appendRegex( "$not" , mg, "i" );

However, the.jsonString() of these two objects are the same. I'm
confused now.
Could you help me understanding this ?

Eliot Horowitz

unread,
Jan 27, 2012, 3:39:27 PM1/27/12
to mongod...@googlegroups.com
I think its a bug.
Can you open a ticket @ jira.mongodb.org

YAC

unread,
Jan 28, 2012, 12:36:54 PM1/28/12
to mongodb-user
submitted
Reply all
Reply to author
Forward
0 new messages