-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
30 lines (25 loc) · 963 Bytes
/
main.js
File metadata and controls
30 lines (25 loc) · 963 Bytes
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
//This is to connect to Atlas
const MongoClient = require('mongodb').MongoClient;
var express = require("express");
var app = express()
// replace the uri string with your connection string.
const uri = "mongodb+srv://admin:admin@cluster1-gw7ks.mongodb.net/test?retryWrites=true&w=majority";
//mongo "mongodb+srv://cluster1-gw7ks.mongodb.net/test" --username admin
MongoClient.connect(uri, function(err, client) {
if(err) {
console.log('Error occurred while connecting to MongoDB Atlas...\n',err);
}
console.log('Connected...');
const collection = client.db("test").collection("devices");
// perform actions on the collection object
client.close();
});
const DATABASE_NAME = "dbproject";
app.post("/createuser", (request, response) => {
collection_users.insert(request.body, (error, result) => {
if(error) {
return response.status(500).send(error);
}
response.send(result.result);
});
});