Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-gridfs

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-gridfs - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

27

lib/schema.js

@@ -21,3 +21,2 @@ 'use strict';

const collection = [gridFSStorage.options.collection, 'files'].join('.');
const model = gridFSStorage.options.model;

@@ -75,7 +74,5 @@ const GridFSSchema = new Schema({

//grab gridfs
const gridfs = mongoose.model(model).gridfs;
//stream file to gridfs
gridfs.write(fileDetails, stream, function (error, createdFile) {
return gridFSStorage.write(fileDetails, stream, function (error,
createdFile) {
if (error) {

@@ -85,3 +82,3 @@ done(error);

//read file details
mongoose.model(model).findById(createdFile._id, done);
gridFSStorage.model.findById(createdFile._id, done);
}

@@ -115,7 +112,4 @@ });

GridFSSchema.methods.read = function (done) {
//grab gridfs
const gridfs = mongoose.model(model).gridfs;
//stream file out of gridfs
return gridfs.readById(this._id, done);
return gridFSStorage.readById(this._id, done);
};

@@ -141,3 +135,3 @@

GridFSSchema.statics.readByFileName = function (filename, done) {
return this.gridfs.readByFileName(filename, done);
return gridFSStorage.readByFileName(filename, done);
};

@@ -159,7 +153,4 @@

GridFSSchema.methods.unlink = function (done) {
//grab gridfs
const gridfs = mongoose.model(model).gridfs;
//obtain file details
mongoose.model(model).findById(this._id, function (error, fileDetails) {
gridFSStorage.model.findById(this._id, function (error, fileDetails) {
if (error) {

@@ -169,3 +160,3 @@ done(error);

//remove file from gridfs
gridfs.unlinkById(fileDetails._id, function (_error /*, id*/ ) {
gridFSStorage.unlinkById(fileDetails._id, function (_error /*, id*/ ) {
done(_error, fileDetails);

@@ -216,3 +207,3 @@ });

GridFSSchema.statics.readById = function (id, done) {
return this.gridfs.readById(id, done);
return gridFSStorage.readById(id, done);
};

@@ -241,3 +232,3 @@

GridFSSchema.statics.unlink = function (id, done) {
this.findById(id).exec(function (error, foundInstance) {
gridFSStorage.model.findById(id, function (error, foundInstance) {
if (error) {

@@ -244,0 +235,0 @@ return done(error);

@@ -8,3 +8,3 @@ 'use strict';

const mongoose = require('mongoose');
const Grid = require('gridfs-stream');
const Grid = require('@lykmapipo/gridfs-stream');
const read = require('stream-read');

@@ -40,6 +40,6 @@

//get either option connection or mongoose connection
const conn = this.options.mongooseConnection || mongoose.connection;
this.conn = this.options.mongooseConnection || mongoose.connection;
//Check if mongoose is connected.
if (conn.readyState !== 1) {
if (this.conn.readyState !== 1) {
throw new Error('Mongoose is not connected');

@@ -49,3 +49,3 @@ }

//initialize grid
this.storage = new Grid(conn.db);
this.storage = new Grid(this.conn.db);

@@ -85,18 +85,23 @@ }

get: function () {
let model;
// create model for the first time
if (!this._model) {
try {
//obtain model if already exists
this._model = this.conn.model(this.options.model);
} catch (e) {
try {
//obtain model if already exists
model = mongoose.model(this.options.model);
} catch (e) {
//build schema
const _schema = schema(this);
//build schema
const _schema = schema(this);
//compile model otherwise
model = mongoose.model(this.options.model, _schema);
//compile model otherwise
this._model = this.conn.model(this.options.model, _schema);
}
}
//export model
return model;
return this._model;
},
// allow user to provide customized model
set: function (v) {
this._model = v;
}

@@ -117,7 +122,13 @@ });

get: function () {
//build schema
const _schema = schema(this);
if (!this._schema) {
//build schema
this._schema = schema(this);
}
//export mongoose compactible schema
return _schema;
//export mongoose compatible schema
return this._schema;
},
// allow user to provide customized schema
set: function (v) {
this._schema = v;
}

@@ -124,0 +135,0 @@ });

{
"name": "mongoose-gridfs",
"version": "0.4.1",
"version": "0.5.0",
"description": "mongoose gridfs on top of gridfs-stream",

@@ -32,3 +32,3 @@ "main": "index.js",

"dependencies": {
"gridfs-stream": "git+https://github.com/lykmapipo/gridfs-stream.git",
"@lykmapipo/gridfs-stream": "^1.2.0",
"lodash": "^4.17.10",

@@ -38,5 +38,5 @@ "stream-read": "^1.1.2"

"devDependencies": {
"async": "^2.6.0",
"async": "^2.6.1",
"chai": "^4.1.2",
"grunt": "^1.0.2",
"grunt": "^1.0.3",
"grunt-contrib-jshint": "^1.1.0",

@@ -49,4 +49,4 @@ "grunt-contrib-watch": "^1.1.0",

"mime": "^2.3.1",
"mocha": "^5.1.1",
"mongoose": "^5.1.0"
"mocha": "^5.2.0",
"mongoose": "^5.2.5"
},

@@ -53,0 +53,0 @@ "engines": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc