如何使用Node.js将https://gitlab.com/api/v4/projects
存储到我的MongoDB中?我调用一个请求函数,该函数得到一个JSON对象,并正确解析了它。我还确保我已连接到我的MongoDB。现在如何将数据传输到数据库?
我尝试过猫鼬,但是我可能做得不正确。我也尝试过功能.insertMany(json, ...)
//git.server.js
const request = require('request');
const options = {
url: 'https://gitlab.com/api/v4/projects',
method: 'GET'
};
request(options, function(err, res, body) {
var json = JSON.parse(body);
console.log(json);
//export to mongodb
});
//app.js
const request = require('request');
const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://<username>:<password>@gitlab-tools-hs5yh.mongodb.net/test?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
const collection = client.db("DBname").collection("User");
console.log('here');
client.close();
});