App crashes with Mongodb (project-type: webview) on Android
emartisoft opened this issue · 1 comments
In sample apps, I tried story-apps. After execute "androidjs build", APK file is created and It works on Android. To connect mongodb, added following code lines but It crashed :(
package.json file content
{
"name": "myapp",
"app-name": "myapp",
"package-name": "mypkg",
"project-type": "webview",
"icon": "./assets/icon/icon.png",
"permission": [
"android.permission.INTERNET",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.READ_EXTERNAL_STORAGE"
],
"version": "1.0.0",
"dist-path": "./dist",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"androidjs": "^2.0.4",
"mongodb": "^4.9.1"
},
"theme": {
"fullScreen": true
}
}
main.js file content (added lines by me only)
>
> back.on("fromFront", function(){
> var MongoClient = require('mongodb').MongoClient;
> var uri = "mongodb://root:123456@mycluster-shard-00-00.xbzha.gcp.mongodb.net:27017,mycluster-shard-00-01.xbzha.gcp.mongodb.net:27017,mycluster-shard-00-02.xbzha.gcp.mongodb.net:27017/?ssl=true&replicaSet=atlas-5h0gg8-shard-0&authSource=admin&retryWrites=true&w=majority";
> MongoClient.connect(uri, function(err, client) {
> const collection = client.db("myDB").collection("myCollection");
> var cursor = collection.find({Ad: 'Murat'});
> cursor.forEach(function(item) {
> if (item != null) {
> //console.log(item.Ad + "\t" + item.Soyad);
> back.send("fromback", item.Soyad);
> }
> }, function(err) {
> if (err) console.log(err);
> client.close();
> });
> });
>
> });
>
index.html content (added lines by me only)
> <body>
>
> ...
>
> <a href="javascript:void(getJSON());">get JSON data</a>
> <h1>data</h1>
> <div id='jsondata'></div>
>
> ...
>
> <script>
>
> function getJSON(){
> front.send("fromFront");
>
> };
>
> front.on("fromback", function(data){
> console.log(data);
> //$('jsondata').html(data);
> document.getElementById('jsondata').innerHTML = data;
> playsid(data);
> });
>
> </script>
>
> ...
>
> </body>
On Windows, It works. On Android, It works but until back.on function and it crashes.
Your advices?
@emartisoft It looks like the old NodeJs version is the reason for that same as #282