我正在通过他们的API从Wundground以JSON格式提取天气数据,没有任何问题.我正在尝试将这些数据存储在MongoDB中供以后使用.我实际上得到了数据,并能够将它写入Mongo的集合中.但是,当我执行db.collection.find()时,它几乎看起来像是单独保存每个单独的字符而不是JSON格式.这是获取数据的代码片段,应该保存到Mongo:
// Define the Wunderground method.
var method = "/api/" + apiKey + "/conditions/q/" + state + "/" + city + ".json";
// Define the HTTP post properties.
var options = {
host: 'api.wunderground.com',
path: method,
method: 'GET',
port: 80
};
// Create the HTTP POST.
var request = http.request(options, function (response) {
var str = '';
// Create the listener for data being returned.
response.on('data', function (chunk) {
str += chunk;
// Create the listener for the end of …Run Code Online (Sandbox Code Playgroud)