merge BSONObj objects, c++

266 views
Skip to first unread message

kafka

unread,
Jan 27, 2012, 6:52:22 AM1/27/12
to mongodb-user
Hello,

I want to build a query with two parameters:

BSONObj title = BSONObjBuilder().appendRegex("title","google").obj();
BSONObj dateRange = BSON(title<<"date" <<
BSONObjBuilder().appendDate("$gt", time(0)*1000-
(3*86400000)).appendDate("$lte", time(0)*1000).obj());

Is there any way to merge these objects?

Thank you for your answer.

YAC

unread,
Jan 27, 2012, 11:19:57 AM1/27/12
to mongodb-user
Try this :
BSONObjBuilder oB;
BSONObj date = BSONObjBuilder().appendDate("$gt", time(0)*1000-
(3*86400000)).appendDate("$lte", time(0)*1000).obj();
date = BSON("date"<<date);
oB.appendElements(date);
oB.appendRegex("title","google");

BSONObj dateRange = oB.obj();
------------------
And I have a question for you. May be you can help :)
I want to execute a "not exist" query.
I can do this in cmd :
db.test.find({$and : [{x:{$not:/.*o.*/}},{x:{$exists:true}}]})
But I don't know how to build a c++ query.
I tried $not with $regex, it doesn't work neither
Do you have any ideas ?

YAC

unread,
Jan 27, 2012, 11:53:02 AM1/27/12
to mongodb-user

BSONObjBuilder oB;
BSONObj date = BSONObjBuilder().appendDate("$gt", time(0)*1000-
(3*86400000)).appendDate("$lte", time(0)*1000).obj();
date = BSON("date"<<date);
oB.appendElements(date);
oB.appendRegex("title","google");

BSONObj dateRange = oB.obj();

On 27 jan, 12:52, kafka <dzidor...@gmail.com> wrote:

YAC

unread,
Jan 27, 2012, 2:09:52 PM1/27/12
to mongodb-user
OK for me with not exist now. :)
Reply all
Reply to author
Forward
0 new messages