0
我需要從我的mongodb數據庫中寫入一個字段到一個json文件。使用節點js。如何去做呢?我沒有找到有用的東西。NodeJS從mongodb訪問變量並寫入JSON文件
我需要從我的mongodb數據庫中寫入一個字段到一個json文件。使用節點js。如何去做呢?我沒有找到有用的東西。NodeJS從mongodb訪問變量並寫入JSON文件
試試這個
var exportDocuments = function (db, callback) {
// Get the documents collection
var collection = db.collection('documents');
// Find some documents
collection.find({}).toArray(function (err, docs) {
require('fs').writeFile('yourFileName.json', JSON.stringify(docs), function (error) {
if (error) return callback(error);
callback();
});
});
}