-
Notifications
You must be signed in to change notification settings - Fork 4
/
mongodb.js
34 lines (28 loc) · 949 Bytes
/
mongodb.js
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
// /Users/harsh/mongodb/bin/mongod.exe --dbpath=/Users/harsh/mongodb-data
// const mongodb = require("mongodb")
// const MongoClient = mongodb.MongoClient
// const ObjectID = mongodb.ObjectID
const { MongoClient, ObjectID} = require("mongodb")
const connectionURL = 'mongodb://127.0.0.1:27017'
const databaseName = 'apnaShow'
const id = new ObjectID()
console.log(id)
console.log(id.getTimestamp())
MongoClient.connect(connectionURL, { useNewUrlParser: true }, (error,client) => {
if (error) {
return console.log('Unable toconnect to database!')
}
const db = client.db(databaseName)
db.collection('users').insertOne({
_id: id,
fname: 'Harsh',
lname: 'Gandhi',
email: '[email protected]',
password: '1'
}, (error,result) => {
if (error) {
return console.log('Unable to insert user')
}
console.log(result.ops)
})
})