json-gridfsbucket
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

json Object to GridFSBucket

Directly JSON Object to GridFSBucket. This package converts JSON object to streamable stringify, then pipe to GridFSBucket.

npm i json-gridfsbucket
import { connect } from 'mongoose';
import { uploadGridFSBucket, downloadGridFSBucket } from "json-gridfsbucket"


const _json = {
    foo: "bar",
    very_big_key_of_value: "VERY_BIG_VALUE"
}

const run = async () => {
    const options = {
        user: "root",
        pass: "example",
        dbName: "test"
    }
    
    const mongoose = await connect('mongodb://localhost:27017', options);
    
    const bucketOptions = {
        mongoose, bucketName: "bucket1", filename: "file.json"
    }

    const _resUpload = await uploadGridFSBucket(_json, bucketOptions)
    console.log("res of upload:", _resUpload)
    /**
     *       {
     *          bucketName: "bucket1",
     *          filename: "file.json"
     *       }
    */

    const _resDownload = await downloadGridFSBucket(bucketOptions)
    console.log("res of download:", _resDownload)
    /**
     *      {
     *          foo: "bar",
     *          very_big_key_of_value: "VERY_BIG_VALUE"
     *      }
     */
}

run()

Package Sidebar

Install

npm i json-gridfsbucket

Weekly Downloads

6

Version

1.0.7

License

ISC

Unpacked Size

16.8 kB

Total Files

6

Last publish

Collaborators

  • inceabdullah