-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53c6b3f
commit 78c7bdb
Showing
3 changed files
with
226 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import mongoose from 'mongoose' | ||
|
||
if (process.argv.length < 3) { | ||
console.error('give password as argument') | ||
process.exit(1) | ||
} | ||
|
||
let password = encodeURIComponent(process.argv[2]) | ||
|
||
let uri = `mongodb+srv://user:${password}@cluster0.10skx.mongodb.net/notes-backend?retryWrites=true&w=majority&appName=Cluster0` | ||
let clientOptions = { | ||
serverApi: { version: '1', strict: true, deprecationErrors: true }, | ||
} | ||
|
||
run().catch(console.dir) | ||
|
||
async function run() { | ||
try { | ||
// Create a Mongoose client with a MongoClientOptions object to set the Stable API version | ||
await mongoose.connect(uri, clientOptions) | ||
await mongoose.connection.db.admin().command({ ping: 1 }) | ||
console.log( | ||
'Pinged your deployment. You successfully connected to MongoDB!', | ||
) | ||
|
||
let noteSchema = new mongoose.Schema({ | ||
content: String, | ||
important: Boolean, | ||
}) | ||
|
||
let Note = mongoose.model('Note', noteSchema) | ||
|
||
// let note = new Note({ content: 'React is cool', important: false }) | ||
// let result = await note.save() | ||
// console.log('note saved!', result) | ||
|
||
let notes = await Note.find({ important: true }) | ||
console.log('saved notes') | ||
for (let note of notes) { | ||
console.log(note) | ||
} | ||
} finally { | ||
// Ensures that the client will close when you finish/error | ||
await mongoose.disconnect() | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
}, | ||
"dependencies": { | ||
"cors": "^2.8.5", | ||
"express": "^4.19.2" | ||
"express": "^4.19.2", | ||
"mongoose": "^8.5.1" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.