iPhone Developer iPhone Developer - 1 year ago 71
JSON Question

using mongodb for caching json responses

Disclaimer: I'm new to NoSQL databases, if something is not clear, appreciate comments and questions to clear things up.

I'm calling some 3rd party web services to get JSON response but need a way to cache the response to avoid repeated calling since each response is constant across remote entities.


I've selected mongodb, is it the right tool for the job, the response entities have lengthy schemas and mongoose is forcing me to define one, is there a way to avoid having to define schema and just save the response by some id and read it later. if someone can kindly help with condition for checking the A. cache and B. saving.

var mongoose = require('mongoose');

if() { // A. condition to check if cached response is available

} else { // call web service
http.request({}, function (response) {
var buffers = [];
response.on('data', function (chunk) {
response.on('end', function () {
var data = Buffer.concat(buffers).toString();
// B. how to save data to a mongoose db

If approach is not right, and I should be using something else then please also enlighten.

Answer Source

If you don't have a schema available then don't use mongoose. Just store the json as mongo documents directly.



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download