Skip to content

inceabdullah/json-gridfsbucket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published