ForerunnerDB icon indicating copy to clipboard operation
ForerunnerDB copied to clipboard

MongoDB Emulation Mode

Open Irrelon opened this issue 10 years ago • 9 comments

This is an issue set up to track a new enhancement to make ForerunnerDB optionally behave exactly like MongoDB when doing CRUD calls.

find - Handle dot-notation style query keys. update - Assume replace instead of update by default.

Implementation is currently suggested to be:

var fdb = new ForerunnerDB();
fdb.mongoEmulation(true);

Irrelon avatar Jun 12 '15 06:06 Irrelon

maybe just {enable,disable}MongoEmulation() ?

YurySolovyov avatar Jul 09 '15 07:07 YurySolovyov

@YuriSolovyov Not sure I follow... could you write the usage in code?

Irrelon avatar Jul 09 '15 08:07 Irrelon

@Irrelon I mean instead of

fdb.mongoEmulation(true);

use

fdb.enableMongoEmulation()

or

fdb.disableMongoEmulation()

just to get rid of true/false flag.

YurySolovyov avatar Jul 09 '15 08:07 YurySolovyov

@YuriSolovyov Ahh I see.

That approach is more terse but increases code size by adding 3 methods to the class instead of 1.

1: fdb.enableMongoEmulation()
2: fdb.disableMongoEmulation()
3: isEnabled = fdb.isMongoEmulationEnabled()

By using a dynamic getter / setter we reduce all these actions down to 1 method call:

1: fdb.mongoEmulation(true)
2: fdb.mongoEmulation(false)
3: isEnabled = fdb.mongoEmulation()

Dynamic getter/setter methods are used throughout ForerunnerDB and are also familiar to those using other libraries like jQuery which make extensive use of them as well.

Irrelon avatar Jul 09 '15 08:07 Irrelon

ok, good point.

YurySolovyov avatar Jul 09 '15 08:07 YurySolovyov

Dev branch now has mongoEmulation() method on fdb, db and collection instances. Find, update and remove all tested and working with dot notation-based queries. Can you guys give it a try and let me know your results?

Irrelon avatar Aug 06 '15 09:08 Irrelon

I haven't implemented the ForerunnerDB in the project I'm working on (when I got involved in the previous issue thread I was comparing and this issue came up), so I can't check the behaviour to verify for you at this point (we moved on and implemented another library) - my apologies! However, this does make it a contender again once we do, which will be soon enough.

kevteljeur avatar Aug 06 '15 10:08 kevteljeur

Out of interest what library did you go with?

Irrelon avatar Aug 06 '15 11:08 Irrelon

I used NeDB (this part of the project is Node.js-based) as an in-memory cache. There's still a requirement for a browser storage component, and if we went with NeDB for that then that would still leave a requirement to abstract the browser storage; NeDB seems to be designed more as a fast, file-backed solution, although it will work in the browser too. We're not using LocalForage yet but it does seem to be the way to go, and obviously ForerunnerDB has that covered.

kevteljeur avatar Aug 06 '15 12:08 kevteljeur