mongoDB中的数据类型

  • Date
mongo shell中提供各式各样的返回日期类型的方法,例如字符串类型或者Date对象类型:
Date()  返回当前的日期字符串;
new Date()  返回使用ISODate()包装的Date对象类型;
ISODate()  返回使用ISODate()包装的Date对象类型;
内部Date对象存储的是64位整形数据(从1970年1月1日到现在时差毫秒数)。
var myDateString = Date();	//返回日期字符串
myDateString			//在shell中输入变量名打印变量值
typeof myDateString		//使用typeof操作符检查类型

//使用 Date()和ISODate() 构造方法返回Date类型
var myDate = new Date();
var myDateInitUsingISODateWrapper = ISODate();
//使用 instanceof操作符合检查类型
myDate instanceof Date				//操作结果true
myDateInitUsingISODateWrapper instanceof Date	//操作结果true

  • ObjectId
mongo shell提供ObjectId()包装类包装ObjectId数据对象。
new ObjectId  		//生成一个新的ObjectId数据

  • NumberLong
通常情况下mongo shell将所有的数据当作浮点值对待。
mongo shell提供NumberLong()包装类处理64位整形数据。
NumberLong("2090845886852")		//NumberLong() 接受一个long类型的字符串
db.collection.insert( { _id: 10, calc: NumberLong("2090845886852") } )

  • NumberInt
mongo shell中提供NumberInt()构造方法表示32位整形数据。



猜你喜欢

转载自blog.csdn.net/user_longling/article/details/52398277