bson的javascript/javascriptwithscope类型有什么用 [英] What is the use of type javascript/javascriptwithscope of bson
问题描述
我想知道这两种类型的bson(javascript/javascriptwithscope)的用法; 作为bson的基本类型.
I am wondering about the use of these two type of bson (javascript/javascriptwithscope); as the base type of bson.
它的用例是什么,以及如何生成javascriptwithscope对象以保存在mongodb中?
What's the use case of it and how to generate a javascriptwithscope object to save in mongodb?
类型编号别名注释
Double 1 "double"
String 2 "string"
Object 3 "object"
Array 4 "array"
Binary data 5 "binData"
Undefined 6 "undefined" Deprecated.
ObjectId 7 "objectId"
Boolean 8 "bool"
Date 9 "date"
Null 10 "null"
Regular Expression 11 "regex"
DBPointer 12 "dbPointer"
JavaScript 13 "javascript"
Symbol 14 "symbol"
JavaScript (with scope) 15 "javascriptWithScope"
32-bit integer 16 "int"
Timestamp 17 "timestamp"
64-bit integer 18 "long"
Min key -1 "minKey"
Max key 127 "maxKey"
推荐答案
基本上,我们不需要执行任何操作:-)数据类型,因为mongo引擎会将正确的类型应用于插入的数据.
Basically we need to do nothing :-) with data type as mongo engine will apply correct type to inserted data.
在创建将插入到mongo中的javascript对象时:
When creating a javascript object which will be inserted to mongo:
var object = {
thisWillBeNumber : 1,
thisWillBeString :"aaa",
thisWillBeAnArray = [1,2,3]
thisWillBeDateTime: new Date()
}
然后mongo使用javascript对象类型并将其保存. 在某些驱动程序/框架中,我们可以在应用程序级别上强制使用字段/变量的类型,并且可以将此类信息添加到存储的文档中.
then mongo uses javascript object type and savs it. In some drivers/framework we can enforce on application level types of our field/variables and such information could be added to stored document.
这篇关于bson的javascript/javascriptwithscope类型有什么用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!