【发布时间】:2015-11-26 11:14:52
【问题描述】:
我有这个代码
var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://localhost:27017/clboTest';
// this could have comed from a form from the browser
var objToInsert = {
_id: 2,
price: 20000,
name: stdin,
description: "20 carat gold ring. ",
//schoolID: { name: 'RUC', address: 'Roskilde', country: 'Denmark' }
};
MongoClient.connect(url, function (err, db) {
var collection = db.collection('products');
collection.insert(objToInsert, function (err, result) {
console.log(result);
db.close();
});
});
我不想硬编码信息(例如价格、名称)。如何在控制台中输入新内容,而不必一遍又一遍地用新信息硬核我的 insert.js 文件?
【问题讨论】:
标签: javascript node.js input console