简体   繁体   English

如何用猫鼬长加减法?

[英]How to add/subtract with Mongoose-long?

I am trying to use mongoose-long for large numbers. 我正在尝试使用猫鼬长的数字。 I'm not sure I am using it correctly. 我不确定我是否正确使用它。 I set the value... 我设定值...

 user = new User({val:12345678901234});

val is mongoose.Schema.Types.Long val是mongoose.Schema.Types.Long

1) What is the correct way to show val, toString()? 1)显示val toString()的正确方法是什么?

2) So how do I manipulate (add, subtract) this value? 2)那么我该如何操作(加,减)该值? Javascript doesn't support full 64bit values, so do I have to do this through mongodb's $inc? Javascript不支持完整的64位值,所以我必须通过mongodb的$ inc做到这一点吗?

Thanks 谢谢

You'd want to use $inc to atomically manipulate the value in the stored docs, but outside of update operations you can use the methods of Long : 您想使用$inc原子地操作存储文档中的值,但是在update操作之外,您可以使用Long方法:

var sum = user.val.add(123);
console.log(sum.toString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM