bson的typejavascript/javascriptwithscope有什么用
What is the use of type javascript/javascriptwithscope of bson
我想知道这两种bson的使用方法(javascript/javascriptwithscope);
作为 bson 的基本类型。
它的用例是什么以及如何生成 javascriptwithscope 对象以保存在 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 引擎会将正确的类型应用于插入的数据。
创建将插入到 mongo 的 javascript 对象时:
var object = {
thisWillBeNumber : 1,
thisWillBeString :"aaa",
thisWillBeAnArray = [1,2,3]
thisWillBeDateTime: new Date()
}
然后 mongo 使用 javascript 对象类型并保存它。
在某些 drivers/framework 中,我们可以强制执行我们 field/variables 的应用程序级别类型,并且可以将此类信息添加到存储的文档中。
我想知道这两种bson的使用方法(javascript/javascriptwithscope); 作为 bson 的基本类型。
它的用例是什么以及如何生成 javascriptwithscope 对象以保存在 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 引擎会将正确的类型应用于插入的数据。
创建将插入到 mongo 的 javascript 对象时:
var object = {
thisWillBeNumber : 1,
thisWillBeString :"aaa",
thisWillBeAnArray = [1,2,3]
thisWillBeDateTime: new Date()
}
然后 mongo 使用 javascript 对象类型并保存它。 在某些 drivers/framework 中,我们可以强制执行我们 field/variables 的应用程序级别类型,并且可以将此类信息添加到存储的文档中。