-
Notifications
You must be signed in to change notification settings - Fork 20
DOCSP-42254: Fix GridFS code #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
norareidy
merged 6 commits into
mongodb:master
from
norareidy:DOCSP-42254-fix-gridfs-code
Aug 8, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,39 @@ | ||
# start create bucket | ||
const db = client.db(dbName); | ||
const bucket = new mongodb.GridFSBucket(db); | ||
# end create bucket | ||
# start create bucket | ||
client = MongoClient("<connection string>") | ||
db = client["db"] | ||
bucket = gridfs.GridFSBucket(db) | ||
# end create bucket | ||
|
||
# start create custom bucket | ||
const bucket = new mongodb.GridFSBucket(db, { bucketName: 'myCustomBucket' }); | ||
# end create custom bucket | ||
# start create custom bucket | ||
custom_bucket = gridfs.GridFSBucket(db, bucket_name="myCustomBucket") | ||
# end create custom bucket | ||
|
||
# start upload files | ||
fs.createReadStream('./myFile'). | ||
pipe(bucket.openUploadStream('myFile', { | ||
chunkSizeBytes: 1048576, | ||
metadata: { field: 'myField', value: 'myValue' } | ||
})); | ||
# end upload files | ||
# start upload files | ||
with bucket.open_upload_stream( | ||
"my_file", chunk_size_bytes=1048576, | ||
metadata={"contentType": "text/plain"}) as grid_in: | ||
grid_in.write("data to store") | ||
# end upload files | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S: i think the line formatting needs to be corrected here |
||
|
||
# start retrieve file info | ||
const cursor = bucket.find({}); | ||
for await (const doc of cursor) { | ||
console.log(doc); | ||
} | ||
# end retrieve file info | ||
# start retrieve file info | ||
for file_doc in bucket.find({}): | ||
print(file_doc) | ||
# end retrieve file info | ||
|
||
# start download files name | ||
bucket.openDownloadStreamByName('myFile'). | ||
pipe(fs.createWriteStream('./outputFile')); | ||
# end download files name | ||
# start download files name | ||
file = bucket.open_download_stream_by_name("my_file") | ||
contents = file.read() | ||
# end download files name | ||
|
||
# start download files id | ||
bucket.openDownloadStream(ObjectId("60edece5e06275bf0463aaf3")). | ||
pipe(fs.createWriteStream('./outputFile')); | ||
# end download files id | ||
# start download files id | ||
file = bucket.open_download_stream(ObjectId('66b3c86e672a17b6c8a4a4a9')) | ||
contents = file.read() | ||
# end download files id | ||
|
||
# start rename files | ||
bucket.rename(ObjectId("60edece5e06275bf0463aaf3"), "newFileName"); | ||
# end rename files | ||
# start rename files | ||
bucket.rename(ObjectId('66b3c86e672a17b6c8a4a4a9'), "new_file_name") | ||
# end rename files | ||
|
||
# start delete files | ||
bucket.delete(ObjectId("60edece5e06275bf0463aaf3")); | ||
# end delete files | ||
# start delete files | ||
bucket.delete(ObjectId('66b3c86e672a17b6c8a4a4a9')) | ||
# end delete files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: why is the code in this file indented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed