-
Notifications
You must be signed in to change notification settings - Fork 20
DOCSP-47282: RawBSONDocument information #176
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,32 @@ The following example reads the sample BSON document from ``file.bson``: | |
|
||
{"address": {"street": "Pizza St", "zipcode": "10003"}, "coord": [-73.982419, 41.579505], "cuisine": "Pizza", "name": "Mongo's Pizza"} | ||
|
||
Work with Raw BSON Data | ||
----------------------- | ||
|
||
You might prefer to use raw BSON documents in certain cases, such as when you move a | ||
document between databases or collections, when you must write binary blobs to a | ||
disk, or when you want to bypass the performance overhead of converting to and from | ||
{+language+} dictionaries. You can use the ``RawBSONDocument`` class to represent raw BSON | ||
documents. To use ``RawBSONDocument`` objects with your collection, set the | ||
``document_class`` parameter of the ``MongoClient`` constructor to ``RawBSONDocument``. | ||
mcmorisi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The following example fetches the sample BSON document from a collection and converts it | ||
to a ``RawBSONDocument``: | ||
mcmorisi marked this conversation as resolved.
Show resolved
Hide resolved
mcmorisi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. code-block:: python | ||
|
||
from bson.raw_bson import RawBSONDocument | ||
|
||
client = pymongo.MongoClient("<connection URI>", document_class=RawBSONDocument) | ||
collection = client["<database name>"]["<collection name>"] | ||
raw_doc = collection.find_one({"name": "Mongo's Pizza"}) | ||
mcmorisi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. note:: | ||
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. Placing a detail so important as a note after the example feels slightly confusing to me: I'd expect documentation to tell me immediately if a certain data representation was read-only or not. 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. I can move this up. |
||
|
||
``RawBSONDocument`` objects are read-only. To modify a ``RawBSONDocument``, you must | ||
first convert it to a {+language+} dictionary. | ||
|
||
API Documentation | ||
----------------- | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.