[ Launch: talk to localhost mongo ] 6180897 by enjalot
-
-
Save enjalot/6180897 to your computer and use it in GitHub Desktop.
talk to localhost mongo
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
{"description":"talk to localhost mongo","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/UEJ512C.png"} |
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
//start mongod with --rest --jsonp | |
//or put rest = true and jsonp = true in you mongo conf | |
//http://localhost:29017 | |
//http://localhost:29017/_commands | |
getMongo({followers:1}, function(err, data) { | |
console.log(data) | |
}) | |
function mongoifyQuery(query) { | |
var keys = Object.keys(query); | |
console.log(keys); | |
var str = ""; | |
var key; | |
for(var i = 0; i < keys.length; i++) { | |
if(i) str +="&"; | |
key = keys[i]; | |
str += "filter_" + key + "=" + encodeURIComponent(JSON.stringify(query[key])) | |
} | |
console.log(str) | |
return str; | |
} | |
function getMongo(query, callback) { | |
var q = mongoifyQuery(query) | |
var url = "http://127.0.0.1:28017/tributary/users/" | |
$.ajax({ | |
url: url, | |
type: "get", | |
data: q, | |
dataType:"jsonp", | |
jsonp:"jsonp", | |
success: function(data) { | |
callback(null, data.rows); | |
}, | |
error: function (XMLHttpRequest, textStatus, error) { | |
callback(error) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment