【发布时间】:2018-06-19 15:32:36
【问题描述】:
请帮我找出合适的解决方案
用户详细信息被存储的集合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 进行比较,所以有什么方法可以执行此任务?
【问题讨论】:
-
所以根据这个打开的ticket它还没有实现
-
但是他们已经发布了3+版本的驱动
-
这是一个非常令人沮丧的问题
-
你的架构是什么?
-
我基本上有两个收藏
标签: node.js mongodb mongodb-query mongodb-lookup