2

Even if i'd use node-mongodb-native, i have to use slightly different functions in slightly different way than the functions i write in mongodb shell.

  1. Why on earth is it better?
  2. Is there way to use absolutely the same syntax as i use in terminal mongodb shell?
  3. If so, are there disadvantages? For example, in case of PostgreSQL there are useful features in middleware like SQL injections prevention etc.

1 Answer 1

4

If you could post an example of two versions of the same functionality that you want to compare then I could give you a better explanation but since you didn't provide any example then I can only speak in general.

Some of the differences are because the Mongo shell executes everything sequentially. In Node you have to use callbacks or promises for flow control which you don't do in the Mongo shell.

Also there are some differences in how you access the collections. In the Mongo shell you usually use db.collectionName.

Also in the Mongo shell you have some things predefined, like functions related to object ids for example.

And finally Mongo uses BSON for data and in Node you use JavaScript object literals (more like JSON but less strict).

Node uses V8 plus additional functionality and Mongo shell uses SpiderMonkey, with no functionality that is available in Node.

It all have consequences in subtle differences.

For more details see:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.