Last active
August 24, 2018 12:16
-
-
Save calindotgabriel/7a8bfcf8ab695735ddd2f58a936497bf to your computer and use it in GitHub Desktop.
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
// import * as cherryPieApi from "../lib/api"; | |
const api = require("./api"); | |
const MongoClient = require('mongodb').MongoClient; | |
const assert = require('assert'); | |
// Connection URL | |
const url = 'mongodb://localhost:27017'; | |
// Database Name | |
const dbName = 'default'; | |
// Collection Name | |
const collName = 'Shops2'; | |
callApi = async () => { | |
const tmpl = await api.getBaseTemplate(); | |
console.log('tmpl:', tmpl) | |
} | |
// callApi() | |
const printjson = (d) => JSON.stringify(d); | |
// Use connect method to connect to the server | |
MongoClient.connect(url, | |
// { server: { | |
// reconnectTries: Number.MAX_VALUE, | |
// reconnectInterval: 1000 | |
// } }, | |
function(err, client) { | |
assert.equal(null, err); | |
console.log("Connected successfully to server"); | |
try { | |
findShops(client); | |
} catch (error) { | |
console.log('errrorr!!') | |
console.log(error.message) | |
} | |
finally { | |
client.close(); | |
} | |
}); | |
function findShops(client) { | |
const db = client.db(dbName); | |
const shopsColl = db.collection(collName); | |
shopsColl.find({}).toArray(function (errc, shopsRes) { | |
let s = shopsRes[0]; | |
shopsRes.forEach(s => { | |
let nearShopsColl = shopsColl.find({ "location": { | |
"$nearSphere": { | |
"$geometry": { | |
"type": "Point", | |
"coordinates": s.location.coordinates | |
} | |
}} }); | |
nearShopsColl.toArray(function (errn, nearShopRes) { | |
assert.notEqual(undefined, nearShopRes) // BOOM | |
}) | |
}) | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment