-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.js
More file actions
45 lines (28 loc) · 1.03 KB
/
basic.js
File metadata and controls
45 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var mongoose = require('mongoose');
import express from 'express';
import request from 'express';
import { MongoClient} from 'mongodb';
const uri = "mongodb+srv://amaredu626:Amar123@cluster0.wjekqoe.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0";
const client = new MongoClient(uri);
var personSchema = mongoose.Schema({
name:String,
age : Number,
nationality: String
});
var Person = mongoose.model("Person",personSchema);
async function run() {
try{
await client.connect();
const db= client.db('newdatabase2');
const collection = db.collection('posts');
// find the documents
const docs= await collection.findOne();
console.log(docs);// printing in console.
// from here i can transfer the values at required frontend places.
}finally{
// closing the database connection when finished or an error occurs
await client.close();
}
}
// function call
run().catch(console.error);