次のMongoDBシェルコードをエミュレートしようとしています。
db.products.find( { $or : [ { title : /blue/i }, { tags : /blue/i } ] }, {_id:0, title:1} );
これは私が試したことです:
bson query[1];
mongo_cursor cursor[1];
bson_init( query );
{
bson_append_start_object( query, "$or");
bson_append_regex( query, "title", "blue", "i" );
bson_append_regex( query, "tags", "blue", "i" );
bson_append_finish_object( query );
}
bson_finish( query );
mongo_cursor_init( cursor, conn, "test.products" );
mongo_cursor_set_query( cursor, query );
while( mongo_cursor_next( cursor ) == MONGO_OK ) {
bson_iterator iterator[1];
if ( bson_find( iterator, mongo_cursor_bson( cursor ), "title" )) {
printf( "%s\n", bson_iterator_string( iterator ) );
}
}
bson_destroy( query );
mongo_cursor_destroy( cursor );
しかし、期待どおりに機能していないようです。また、オブジェクトを配列に置き換えてから、オブジェクト内に配列をネストしようとしましたが、役に立ちませんでした。