Mongodb c++ bson query

瀏覽次數:100 次
跳到第一則未讀訊息

Chandan L

未讀,
2016年10月2日 下午2:06:552016/10/2
收件者:BSON
Hi All,

I am trying to build mongo query for expression "_id or name and age" in c++.
Function builds this query are not implemented in multiple functions. Top level function creates bsont_t object and initialised and subsequent function calls uses bson_append_array_begin pair . What is the best way to clean up memory? Just calling destroy at top level shall clean up memory?

Thanks

Dwight Merriman

未讀,
2016年10月2日 晚上11:17:592016/10/2
收件者:bs...@googlegroups.com
note that since this is partially a query question if you need more help you may get more replies on the mongodb_user google group...

you may have already viewed has info: 


for somehting like this json: 

  $or: [
    { _id : 123 },
    { $and : [ { name:"abc" }, { age:33 } ] }
  ]
}

i believe it would be something like 

bsoncxx::builder::stream::document b;
b << 
  "$or" << open_array << 
    open_document << "_id" << 123 << close_document << 
    open_document << 
      "$and" << open_array << 
        open_document << "name" << "abc" << close_document << 
        open_document << "age" << 33 << close_document <<
      close_document << 
    close_array << 
  close_array;

auto cursor = db["mydb"].find(b.view());

i believe the cleanup is automatic when 'b' above destructs.

if above seems verbose you could make local shorthands within a given function or file scope e.g.: 

auto &open_document_type D = open_document;
auto &open_document_type D_ = close_document;

see also 









--
You received this message because you are subscribed to the Google Groups "BSON" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bson+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

回覆所有人
回覆作者
轉寄
0 則新訊息