npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongoose-gridfs-extra

v1.0.1

Published

A simple wrapper for the Mongoose GridFSBucket-API

Downloads

4

Readme

mongoose-gridfs-extra

GitHub package.json dynamicnpm type definitions

Top LanguageCode SizeNPM Bundle SizeLicense

npm dev dependency versionnpm dev dependency versionnpm dev dependency versionDependencies

Goto CounterGithub DownloadsGitHub issuesGithub pull requestsGitHub last commit

NPM DownloadsGitHub package.json version (subfolder of monorepo)

A simple wrapper for the Mongoose GridFSBucket-API. If you need a similar wrapper for Mongodb GridFSBucket-API, see gridfs-extra

This package is designed to avoid operations on the stream objects provided by the native API, thereby saving time.

Install

install npm package

npm install mongoose-gridfs-extra

or clone from Github

# ssh
git clone [email protected]:peachest/mongoose-gridfs-extra.git

# http
git clone https://github.com/peachest/mongoose-gridfs-extra.git

Usage

Complete runnable example is provided. See example/example.{cjs,mjs}.

After cloning the repository to local, run:

cd mongoose-gridfs-extra
node example/example.cjs
node example/example.mjs

Import

// ESModule
import * as gridfs from "mongoose-gridfs-extra"
import mongoose from "mongoose"

// or CommandJS
const {mongoose} = require('mongoose')
const gridfs = require("mongoose-gridfs-extra")

Connect to Mongodb Server

const uri = 'mongodb://localhost:27017/test';
const connect = await mongoose.createConnection(uri).asPromise()

Create GridFS bucket

const db = connect.db
const bucketName = "testBucket";
const options = {
    bucketName
}

// mongoose-gridfs-extra
const bucket = gridfs.createGridFSBucket(db, options)
// or mongodb native API
const bucket = new mongoosemongodb.GridFSBucket(db, options) ;

Write file into bucket

// Read Buffer type file content
const fileName = ""
let file = await fs.readFile("")

// Write file into bucket
const gridFSFile = await gridfs.writeFileByName(bucket, file, fileName)
const id = gridFSFile._id

Read file from bucket

// Read file from bucket
file = await gridfs.readFileById(bucket, id)
// or use fileName
file = await gridfs.readFileByName(bucket, fileName, {
    revision: -1 // default value
})

:warning: A bucket can store files with the same name. If you wonder how the bucket will retrun when read file by name, see the following native doc from mongodb gridfs bucket:

If there are multiple files with the same name, this will stream the most recent file with the given name (as determined by the uploadDate field). You can set the revision option to change this behavior.

As for the revision:

The revision number relative to the oldest file with the given filename.

  • 0 gets you the oldest file,
  • 1 gets you the 2nd oldest,
  • -1 gets you the newest.

License

Apache 2.0