为什么nodejs-mongodb中间件与mongo shell的语法不同? [英] Why nodejs-mongodb middleware has different syntax than mongo shell?

查看:117
本文介绍了为什么nodejs-mongodb中间件与mongo shell的语法不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使我要使用 node-mongodb-native ,我也必须使用的功能与我在mongodb shell中编写的功能略有不同的方式使用稍有不同的功能.

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. 为什么在地球上会更好?
  2. 有没有办法使用与终端中使用的语法完全相同的语法 mongodb shell?
  3. 如果是这样,是否有不利条件?例如,对于PostgreSQL,中间件中有一些有用的功能,例如SQL注入预防等.
  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.

推荐答案

如果您可以发布要比较的同一功能的两个版本的示例,那么我可以为您提供更好的解释,但是由于您没有提供那么任何一个例子我只能说一般.

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.

某些差异是因为Mongo Shell顺序执行所有操作.在Node中,您必须使用回调或Promise进行流控制,而在Mongo Shell中则不需要.

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.

访问集合的方式也有所不同.在Mongo Shell中,通常使用db.collectionName.

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

在Mongo Shell中,您还预定义了一些东西,例如与对象ID相关的功能.

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

最后,Mongo使用BSON进行数据,在Node中使用JavaScript对象文字(更像JSON,但不那么严格).

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

Node使用V8和其他功能,而Mongo shell使用SpiderMonkey,而Node中没有可用的功能.

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:

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆