-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
69 lines (66 loc) · 2.89 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const express = require('express');
const app = express()
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
app.get('/', async (req, res) => {
start_of_cosmos = Date.now()
count = 0
// Import database node module
const CosmosClientInterface = require("@azure/cosmos").CosmosClient;
// Database and container IDs
const databaseId = "ToDoList";
const containerId = "Instagram-container";
// Configure database access URI and primary key
const endpoint = "https://test-cosmos-db-data.documents.azure.com:443/";
const authKey = "igNoCXUZLwLfDlYZUrXXCy5XcWcqmZMkUZN1OWNz5yEQfyJtyVSNxXhikBTHi5wFx5cI9IsyfpzJACDb3w4QVg==";
// Instantiate the cosmos client, based on the endpoint and authorization key
const cosmosClient = new CosmosClientInterface({
endpoint: endpoint,
auth: {
masterKey: authKey
},
consistencyLevel: "Session"
});
try {
// Open a reference to the database
const dbResponse = await cosmosClient.databases.createIfNotExists({
id: databaseId
});
var database = dbResponse.database;
const { container } = await database.containers.createIfNotExists({id: containerId,partitionKey:"dir_country_name"});
// const newItemId = Math.floor(Math.random() * 1000 + 10).toString();
// let documentDefinition = {"post_id":"Bsgwm-oFWhX","cts_x":"2019-01-11 17:58:02.000","post_type":1,"number_likes":42,"number_comments":0,"profile_name":"serenazilio.mua","following":949,"followers":522,"n_posts":451,"is_business_account":true,"name":"La Proseccheria","dir_city_name":"Padua","dir_country_name":"Italy","lat":11.87435,"lng":45.40847,"cts_y":"2019-05-26 16:48:28.205"};
// Add a new item to the container
console.log("** Comparision **");
//to add data to container
// var json = require('./five_chunk.json')
// for (let i = 0; i < json.length; i++) {
// count++
// const createResponse = await container.items.create(json[i]);
// }
const {result:results} = await container.items.query("SELECT * FROM c WHERE c.post_id='BwxDyPfndJS'", {enableCrossPartitionQuery: true}).toArray();
console.log(results);
end_of_cosmos = Date.now()
console.log("cosmos time: ")
console.log(end_of_cosmos-start_of_cosmos)
start_of_mongo = Date.now()
MongoClient.connect(url, (err, db) => {
if (err)
throw err;
var dbo = db.db("insta");
dbo.collection("instadata").find({ post_id: "BwxDyPfndJS" }).toArray(function (err, result) {
if (err)
throw err;
db.close();
end_of_mongo = Date.now();
console.log("mongoDB time: ")
console.log(end_of_mongo - start_of_mongo);
});
});
res.send(results);
} catch (error) {
console.log(error);
res.status(500).send("Error with database query: " + error.body);
}
});
app.listen(3000, () => console.log('Example app listening on port 3000!'))