Skip to content

Commit 6087262

Browse files
committed
nb edits
1 parent 4b44694 commit 6087262

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

snooty.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ driver-short = "Node.js driver"
3131
mdb-server = "MongoDB Server"
3232
min-node-version = "v16.20.1"
3333
stable-api = "Stable API"
34-
language = "Javascript"
34+
language = "JavaScript"

source/data-formats/bson.txt

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,15 @@ The following example writes the sample BSON document to ``file.bson``:
9090

9191
.. code-block:: javascript
9292

93-
const fs = require('fs'); // Import the file system module
94-
const BSON = require('bson'); // Import the BSON package
93+
import fs from 'fs/promises'; // Import the file system module
94+
import { BSON } from 'bson'; // Import the BSON package
9595

9696
// Create a BSON object
9797
const bsonData = BSON.serialize(result);
9898

9999
// Write the BSON data to a file
100-
fs.writeFile('file.bson', bsonData, (err) => {
101-
if (err) throw err;
102-
console.log('BSON data written to file.bson');
103-
});
100+
await fs.writeFile('file.bson', bsonData);
101+
console.log('BSON data written to file.bson');
104102

105103
Read BSON from a File
106104
---------------------
@@ -116,25 +114,23 @@ The following example reads the sample BSON document from ``file.bson``:
116114
.. input::
117115
:language: javascript
118116

119-
const fs = require('fs'); // Import the file system module
120-
const BSON = require('bson'); // Import the BSON package
117+
import fs from 'fs/promises'; // Import the file system module
118+
import { BSON } from 'bson'; // Import the BSON package
121119

122120
// Read the BSON data from a file
123-
fs.readFile('file.bson', (err, data) => {
124-
if (err) throw err;
125-
const document = BSON.deserialize(data);
126-
console.log(document);
127-
});
121+
const data = await fs.readFile('file.bson');
122+
const document = BSON.deserialize(data);
123+
console.log(document);
128124

129125
.. output::
130126
:visible: false
131127

132128
{
133-
_id: new ObjectId('67e1823d0d63bfdf87e8928e'),
134-
"address": {"street": "Pizza St", "zipcode": "10003"},
135-
"coord": [-73.982419, 41.579505],
136-
"cuisine": "Pizza",
137-
"name": "Mongo's Pizza"
129+
_id: new ObjectId('67e1823d0d63bfdf87e8928e'),
130+
address: { street: 'Pizza St', zipcode: '10003' },
131+
coord: [ -73.982419, 41.579505 ],
132+
cuisine: 'Pizza',
133+
name: "Mongo's Pizza"
138134
}
139135

140136
API Documentation

0 commit comments

Comments
 (0)