我是nodejs的新手,两天以来,我一直试图弄清楚它是如何与mongoskin和express一起工作的,但不知何故,我没有运气。需要有人帮忙。我需要编辑这个集合。
router.get('/edit/:name', function(req, res){
var db = req.db;
var n = req.params;
console.log(n); // will only output the selected name.
if(!n){res.send('not found query')}
else{
db.collection('uList').find(n, function(err, docs){
res.json(docs);
});
};
});下面是我的收藏:
{"_id": ObjectId("1341354563458567845678"), "name": "fritz", "age": 19, "info": "fritz was here"}
{"_id": ObjectId("9676524234861346897543"), "name": "Susi", "age": 21, "info": "Susi was here too"}这里是我的app.js
var mongo = require('mongoskin');
var db = mongo.db('mongodb://localhost:27017/sample', {native_parser:true});输出结果只会返回名称
{"name": "fritz"}非常感谢你的帮助。
发布于 2015-03-29 19:50:10
已解决!!如果有人像我一样有问题,试试这个。
db.collection('uList').find(n).toArray(function(err, n){
res.json(n);
});将得到如下输出
{"_id": ObjectId("9676524234861346897543"), "name": "Susi", "age": 21, "info": "Susi was here too"}谢谢。
https://stackoverflow.com/questions/29327314
复制相似问题