我正在尝试模拟以下 MongoDB shellcode:
db.collection.find( { $and: [ { $or: [ { document: { field: "X" } }, { field: "X" } ] }, { _id: ObjectId("X") } ] } );
这是我尝试过的(使用新的 MongoDB-C-Driver):
bson_init(&query);
bson_append_document_begin(&query, "$and", 4, &and);
bson_append_oid(&and, "_id", 3, oid);
bson_append_document_begin(&and, "$or", 3, &or);
bson_append_utf8(&query, "field", 5, "X", 1);
bson_append_document_end(&and, &or);
bson_append_document_begin(&and, "$or", 3, &or);
bson_append_utf8(&query, "document.field", 14, "X", 1);
bson_append_document_end(&and, &or);
bson_append_document_end(&query, &and);
collection = mongoc_client_get_collection (client, "db", "collection");
cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 1, 0, &query, NULL, NULL);
if(mongoc_cursor_next(cursor, &doc)){
printf("> Field found\r\n");
}
先感谢您。
此致。