These types of activities are best done directly in JS side, with e.g. a
--js-library myMongoLibrary.js integration, rather than attempting to adapt
each JS code line to be called from C++ (in a JNI-style fashion). The JS
libraries allow storing both state and functions on JS side, which makes it
easier to store database objects and other things that don't need to be
marshalled over to C++ side, but can be pointed to via using some kind of
custom opaque handle. See the Emscripten src/library_xxx.js files for
example usage, they use this facility.

2016-10-10 17:24 GMT+03:00 <r0l...@freemail.hu>:

> Hi All,
>
> I'm trying to instantiate a mongodb client and open it via emscripten::val
> but I'm already stuck at the beginning:( What I'm trying achieve first, is
> step 3 of this mongodb doc: https://docs.mongodb.com/
> getting-started/node/client/ which is this js oneliner: "var MongoClient =
> require('mongodb').MongoClient;"
>
> In the consturctor of my c++ class I have:
>
> js_db::js_db(){
> emscripten::val require = emscripten::val::global("require");
> emscripten::val mongoModule = require(std::string("mongodb"));
> emscripten::val mongoClient = mongoModule.MongoClient();
> //TODO: register objIDs in global objectTracker table;
> }
>
> The error I get is: "no member named 'MongoClient' in 'emscripten::val' ".
> What am I doing wrong? Why don't I get it in case of mongoModule?
>
> What I'd like to achieve then, based on this earlier suggestion of this
> group ( https://groups.google.com/d/msg/emscripten-discuss/7-
> i5pRK7edQ/-MrCNVAuCAAJ ) is to call mongoClient.connect() like:
>
> void js_db::open(const std::string& db_uri){
> this->db_uri=db_uri;
> EM_ASM_({
> var db_uri = Module.Pointer_stringify($0);
> var mongoClient = objectTracker[$1];
> //TODO: MongoClient.connect(db_uri, function(err, db)
> },db_uri.c_str(),mongoClientObjId);
> }
>
> Thanks for any help in advance!
>
> Best regards,
> r0ller
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to emscripten-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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

Reply via email to