Tag: mongo collection

使用Node.js和Express.js检索MongoDB子文档

我使用node.js,express.js和mongodb创build了一个RESTful API。 我开始创build我的路线,从一个完美的MongoDB集合中提取文档。 示例集合文档 { "_id" : ObjectId("51ace8c04cc8ea865df0923e"), "title" : "Some Example Title", "producer" : { "company" : "Your Company Name" } } 工程 – 它也适用,如果我做.find({查询}),而不是一般的find() app.get('/something', something.findAll); exports.findAll = function(req, res) { db.collection('something', function(err, collection) { collection.find().toArray(function(err, items) { res.contentType('json'); res.header("Access-Control-Allow-Origin", "*"); res.header('Access-Control-Allow-Methods', 'GET, PUT'); res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization'); res.send(items); }); }); }; 但是当我尝试调用一个embedded式文档(即子文档)它使用dot.notation它打破。 * […]