2

I have NodeJS app that uses MongoDB as database. I'm using native mongo driver (not mongoess).

The application allow users to work on projects and share them and the logic that decide which projects a user is allowed to see is built as mongo criteria selector.

In order to test that I've found TingoDB which looks like a great candidate for mocking the MongoDB to be able to run the real model code and check that it is working.

My question is what is the best way to load the initial data? keep it in separate file? Keep it as another model?

Thank you, Ido.

Ido Ran
  • 10,584
  • 17
  • 80
  • 143

1 Answers1

2

TingoDB actually stores it's data in flat-files, so if you want, you could just keep a copy of the database in a directory and load that.

However, if you're just testing with a small amount of data, you'd probably be better off keeping the test-data as in your testing scripts, and inserting it through your application as part of the test. That way, you can easily compare the data in the application to the data you loaded in your assertions.

Finally, if you're running MongoDB in production, then you should probably use MongoDB in your tests. While they do have nearly identical APIs, they have very different performance, which should be something you're keeping track of in testing. Unless there's a need to use TingoDB during testing, I'd try to make it as similar to the production environment as possible.

slang
  • 626
  • 7
  • 26
  • Thank you very much for the detailed answer. I want to use TingoDB to do unit test to validate the code in my DAL is correct. Things such as ensure a user sees only the project he should see and nothing else. I understand that the perf is very different - I'm only interested in correctness at this point. – Ido Ran Mar 03 '15 at 10:03
  • 1
    Ah, that makes sense. I'd still be hesitant to run tests on a different db than I use in production if there isn't a test run on MongoDB before deploying. Is there any reason why you can't use Mongo while testing? – slang Mar 03 '15 at 19:47
  • The main reason is speed, I thought tingodb is much faster to start and stop since everything is in-memory – Ido Ran Mar 05 '15 at 04:56
  • Oh, it's actually quite a bit slower... which is ok if you're using it with medium/small datasets in places that setting up MongoDB would be a pain, but if you're going for speed then it's not what you want. See: http://www.tingodb.com/info/features/ - "TingoDB is not super fast, but very close to what you can expect from MongoDB on reasonable sized data-sets. In average we estimate that it 1 to 2 times slower that MongoDB which not so bad for pure JavaScript solution." – slang Mar 05 '15 at 17:19
  • My dataset is very small, you say that using MongoDB that will access the file system will be faster than TingoDB in-memory implementation? – Ido Ran Mar 06 '15 at 18:08