我有两个集合(工资和用户),我想获取id(在用户集合中)和pid(在salaries集合中)匹配的两个集合的所有记录,但是我要从薪金集合中获取所有数据这是我的代码错误
app.post('/getdata', (req, res, next) =>
{
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://127.0.0.1:27017/";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
dbo.collection('salaries').aggregate([
{ $lookup:
{
from: 'users',
localField: 'pid',
foreignField: '_id',
as: 'orderdetails'
}
}
]).toArray(function(err, res) {
if (err) throw err;
console.log(JSON.stringify(res));
db.close();
});
});
res.send("Get data");
})