https://github.com/mongoosejs/mongoose-long
Provides Number Long support for Mongoose
https://github.com/mongoosejs/mongoose-long
Last synced: over 1 year ago
JSON representation
Provides Number Long support for Mongoose
- Host: GitHub
- URL: https://github.com/mongoosejs/mongoose-long
- Owner: mongoosejs
- License: mit
- Created: 2012-08-01T16:43:04.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2023-11-01T02:08:47.000Z (over 2 years ago)
- Last Synced: 2025-04-02T21:18:44.808Z (over 1 year ago)
- Language: JavaScript
- Size: 44.9 KB
- Stars: 79
- Watchers: 3
- Forks: 16
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mongoose-plugins - mongoose-long - long?style=flat&label=%20) |  |  | Adds support for 64-bit integers (`Long`) in Mongoose schemas, enabling storage of large numeric values. | (🛠General Utilities)
README
#mongoose-long
===============
Provides Number Long support for [Mongoose](http://mongoosejs.com).
[](http://travis-ci.org/mongoosejs/mongoose-long)
Example:
```js
const mongoose = require('mongoose')
require('mongoose-long')(mongoose);
const {Types: {Long}} = mongoose;
const partSchema = new Schema({
long: {
type: Long,
}
});
const Part = db.model('Part', partSchema);
const part = new Part({long: '9223372036854775806'});
part.long = part.long.divide(Long.fromString('2'));
part.save()
```
### install
```
npm install mongoose-long
```
See [node-mongodb-native](https://mongodb.github.io/node-mongodb-native/4.2/classes/Long.html) docs on all the `Long` methods available.
[LICENSE](https://github.com/aheckmann/mongoose-long/blob/master/LICENSE)
### TypeScript Usage
Make sure you enable both `compilerOptions.allowSyntheticDefaultImports` and `compilerOptions.esModuleInterop` in your `tsconfig.json`.
```typescript
import mongoose from 'mongoose';
import mongooseLong from 'mongoose-long';
mongooseLong(mongoose);
const Long = mongoose.Schema.Types.Long;
```