The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

//!/usr/bin/rperl
// [[[ HEADER ]]]
#include <rperlstandalone.h>
#include <RPerl/Support/MongoDBStandAlone.h> // MANUALLY MODIFIED, NEED FIX!!!
#ifndef __CPP__INCLUDED__mongodb_insert_one_find_one_cpp
#define __CPP__INCLUDED__mongodb_insert_one_find_one_cpp 0.001_000
# ifdef __CPP__TYPES
// [[[ INCLUDES ]]]
int main() {
// [[[ OPERATIONS HEADER ]]]
// [[[ OPERATIONS ]]]
// my MongoDB::MongoClient $my_client = MongoDB::MongoClient->new({host => 'mongodb://localhost:27017'});
MongoDB__MongoClient my_client {mongodb_host{"mongodb://localhost:27017"}};
// my string $my_database_name = 'rperl_test_database';
string my_database_name = (const string) "rperl_test_database";
// print {*STDERR} 'have $my_database_name = ', $my_database_name, "\n";
prerr "have $my_database_name = " << my_database_name << endl;
// my MongoDB::Database $my_database = $my_client->mongodb_get_database($my_database_name);
// MongoDB__Database my_database = my_client[my_database_name]; // NO SUPPORT, unwrapped calling convention, OO
// MongoDB__Database my_database = my_client->mongodb_get_database(my_database_name); // NO SUPPORT, wrapped calling convention, OO
MongoDB__Database my_database = mongodb_get_database(my_client, my_database_name); // YES SUPPORT, wrapped calling convention, procedural
// my string $my_collection_name = 'rperl_test_collection';
string my_collection_name = (const string) "rperl_test_collection";
// print {*STDERR} 'have $my_collection_name = ', $my_collection_name, "\n";
prerr "have $my_collection_name = " << my_collection_name << endl;
// my MongoDB::Collection $my_collection = $my_database->mongodb_get_collection($my_collection_name);
// MongoDB__Collection my_collection = my_database[my_collection_name]; // NO SUPPORT, unwrapped calling convention, OO
// MongoDB__Collection my_collection = my_database->mongodb_get_collection(my_collection_name); // NO SUPPORT, wrapped calling convention, OO
MongoDB__Collection my_collection = mongodb_get_collection(my_database, my_collection_name); // YES SUPPORT, wrapped calling convention, procedural
// my bson_document $my_document = {
bson_document my_document = bson_begin
// name => 'rperl_test_data',
<< "name" << "rperl_test_data"
// source => 'Perl',
<< "source" << "C++"
// foo_integer => my integer $TYPED_foo_integer = 1,
<< "foo_integer" << 1
// foo_string_arrayref => my bson_arrayref $TYPED_foo_string_arrayref = ['abc', 'def', 'ghi'],
<< "foo_string_arrayref" << bson_arrayref_begin
<< "abc" << "def" << "ghi"
<< bson_arrayref_end
// foo_integer_hashref => my bson_hashref $TYPED_foo_integer_hashref = { x => 203, y => 102 }
<< "foo_integer_hashref" << bson_hashref_begin
<< "x" << 203
<< "y" << 102
<< bson_hashref_end
// };
<< bson_end;
// bson_document my_document = bson_begin << "name" << (const string) "rperl_test_data" << "source" << (const string) "Perl" << "foo_integer" << 1 << "foo_string_arrayref" << bson_arrayref_begin << (const string) "abc" << (const string) "def" << (const string) "ghi" << bson_arrayref_end << "foo_integer_hashref" << bson_hashref_begin << "x" << 203 << "y" << 102 << bson_hashref_end << bson_end;
// my MongoDB::InsertOneResult $my_result = $my_collection->mongodb_insert_one($my_document);
// MongoDB__InsertOneResult my_result = my_collection.insert_one(my_document.view()); // NO SUPPORT, unwrapped calling convention, OO
// MongoDB__InsertOneResult my_result = my_collection->mongodb_insert_one(my_document); // NO SUPPORT, wrapped calling convention, OO
MongoDB__InsertOneResult my_result = mongodb_insert_one(my_collection, my_document); // YES SUPPORT, wrapped calling convention, procedural
// my bson_document__optional $my_found_data = $my_collection->mongodb_find_one({ name => 'rperl_test_data' });
// bson_document__optional my_found_data = my_collection.find_one(bsoncxx::builder::stream::document{} << "name" << "rperl_test_data" << bsoncxx::builder::stream::finalize); // NO SUPPORT, unwrapped calling convention, OO
// bson_document__optional my_found_data = my_collection->mongodb_find_one(bson_begin << "name" << (const string) "rperl_test_data" << bson_end); // NO SUPPORT, wrapped calling convention, OO
bson_document__optional my_found_data = mongodb_find_one(my_collection, bson_begin << "name" << (const string) "rperl_test_data" << bson_end); // YES SUPPORT, wrapped calling convention, procedural
// if ($my_found_data) {
if (my_found_data) {
// print {*STDERR} 'have $my_found_data = ', Dumper($my_found_data), "\n";
// prerr "have $my_found_data = " << bsoncxx::to_json(*my_found_data) << endl; // NO SUPPORT, unwrapped calling convention, procedural
prerr "have $my_found_data = " << bson_Dumper(my_found_data) << endl; // YES SUPPORT, wrapped calling convention, procedural
}
// else {
else {
// print {*STDERR} 'have NO $my_found_data', "\n";
prerr "have NO $my_found_data" << endl;
}
// [[[ OPERATIONS FOOTER ]]]
return 0;
}
// [[[ FOOTER ]]]
# elif defined __PERL__TYPES
Purposefully_die_from_a_compile-time_error,_due_to____PERL__TYPES_being_defined.__We_need_to_define_only___CPP__TYPES_in_this_file!
# endif
#endif