Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent datastore not working #24

Closed
vincentneuts opened this issue Feb 21, 2018 · 7 comments
Closed

Persistent datastore not working #24

vincentneuts opened this issue Feb 21, 2018 · 7 comments

Comments

@vincentneuts
Copy link

vincentneuts commented Feb 21, 2018

I tried to create a persitent datastore like this:

var Datastore = require('react-native-local-mongodb');
var db = new Datastore({ filename: 'data',autoload:true});
var doc = { hello: 'world'  };
db.insert(doc);
db.find({}, function (err, docs) {
                console.log(docs);
 });

It didn't insert or find anything but, If I use it in memory like below. Then it works fine and just returns the doc that's inserted into it.

var Datastore = require('react-native-local-mongodb');
var db = new Datastore();
var doc = { hello: 'world'  };
db.insert(doc);
db.find({}, function (err, docs) {
                console.log(docs);
 });

Are there any android permissions that need to be set?

Update:

When performing insert, find or remove in an async function with wait before it it never finishes.

@antoniopresto
Copy link
Owner

Which version are you using?

@vincentneuts
Copy link
Author

"dependencies": {
"react-native-local-mongodb": "^1.9.1",
"react": "16.2.0",
"react-native": "0.52.0"
........
}

and npm 4.6.1

@antoniopresto
Copy link
Owner

I can not test on android now. Can you try react-native-local-mongodb@1.9.2 ?

@antoniopresto
Copy link
Owner

please, try 2.0.0

@vincentneuts
Copy link
Author

vincentneuts commented Feb 25, 2018

installed 2.0.0.

the persistance db works fine when running test, but skips inserting data when using android (6.0.1). did not try it on IOS

example of a scenario:

async function insert(){
    var testdb = await new Datastore({ filename: 'asyncStorageKey', autoload: true });
    console.log("Start persitence");
    await testdb.insertAsync({ name: 'Bob' })
    console.log("inserted")
    const items = await testdb.findAsync({})
    console.log(items);
    console.log("end test");
}

outcome:
only the first console.log will be executed.

Test:

import Datastore from "react-native-local-mongodb"
it('update with promise', async () => {
  const db = await new Datastore({filename: "test" , autoload: true })
  const items0 = await db.findAsync({})

  await db.insertAsync({ name: 'Maggie' })
  await db.insertAsync({ name: 'Bob' })

  const items = await db.findAsync({})

  const maggie1 = await db.findOneAsync({ name: 'Maggie' })
  const bob1 = await db.findOneAsync({ name: 'Bob' })

  await db.updateAsync({ name: { $in: ['Maggie', 'Bob'] } }, { $set: { age: 1 } }, { multi: true })

  const maggie2 = await db.findOneAsync({ name: 'Maggie' })
  const bob2 = await db.findOneAsync({ name: 'Bob' })

  expect(items0).toHaveLength(0)
  expect(items).toHaveLength(2)
  expect(maggie1.age).toBeUndefined()
  expect(bob1.age).toBeUndefined()
  expect(bob2.age).toEqual(1)
  expect(maggie2.age).toEqual(1)
})

Test Passed

@vincentneuts
Copy link
Author

Solved:

It had something to do with the chrome debugging. -> Stopt debugging, restarted everything and it suddenly worked. Thanks for the help!

@vincentneuts
Copy link
Author

vincentneuts commented Feb 25, 2018

Solved:

It had something to do with the chrome debugging. -> Stopt debugging, restarted everything and it suddenly worked. Thanks for the help!

source:
facebook/react-native#7605

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants