请帮我找到合适的解决方案
集合被存储用户详细信息app_users
{
_id: {
$oid: "abcd1235a6ad4a56dadasd"
},
user_name: "vikas Kandari",
user_dp: "ASDAD486412.jpg"
}
用户预订存储的集合
{
_id : {
$oid : "asdasdasdasdasd"
},
user_id : "abcd1235a6ad4a56dadasd",
booking_item : "some product",
booking_date : "datetime"
}
我正在使用的查找(左连接)查询是
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
const url = 'mongodb://root:root@localhost:3000/app';
const dbName = 'app';
MongoClient.connect(url, function(err, client) {
assert.equal(err, null);
console.log("Connected successfully to server");
const db = client.db(dbName);
const collection = db.collection('users');
collection.aggregate([{
$lookup: {
from: 'bookings',
localField: '_id',
foreignField: 'user_id',
as: 'bookings'
}
}]).toArray(function(err, docs) {
assert.equal(err, null);
console.log(docs);
});
client.close();
});
我想从用户集合中选择具有相应用户详细信息的预订,但它返回空白,因为 mongodb 正在将字符串与 objectId 进行比较,所以有什么方法可以执行此任务?