scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
556 stars 80 forks source link

find() not returning all results #113

Closed wjessup closed 6 years ago

wjessup commented 6 years ago

I'm writing an electron app and have various db functions in a module that is loaded in main process and in the render process.

When the app loads in main I can do something like Project.find(...) and get 7 results ( correctly ). I do the same in the render to load a list for display, call the same function from the same module, get 7 results (correctly).

Then I execute an action to save a new Project in main process.

After that I do the same .find() and get 8 results (correctly). In the callback where I log 8 results, I launch an event to do the .find() in the render.

It executes and I get 7 results (incorrect!).

Code in main process:

Project.find({ user: user._id }).then(projects => { console.log(projects.length) // => 8 results global.mainWindow.webContents.send('projects:changed') //triggeres render event as below })

in render process:

ipcRenderer.on('projects:changed', (e,arg) => { Project.find({ user: user._id }).then(projects => { console.log(projects) // => 7 results. self.setState({ projects }) }) })

Keep in mind this works as expected on app launch.

I'm stumped.

wjessup commented 6 years ago

nm, read that this is related to each instance not looking at the JSON files but holding its own data in memory.