猫鼬$ lookup,其中localField是foreignField中ObjectId的字符串 [英] Mongoose $lookup where localField is a string of an ObjectId in foreignField

查看:466
本文介绍了猫鼬$ lookup,其中localField是foreignField中ObjectId的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个$ lookup,其中localField是一个ObjectId的字符串表示形式,而外来字段是一个实际的ObjectId.

I want to do a $lookup where the localField is a String representation of an ObjectId and the foreign field is an actual ObjectId.

您是否知道,如果项目是字符串值而_id是ObjectId,那么MongoDB 3.2是否可以实现?

Any idea if this is possible with MongoDB 3.2 if items is a String value but _id is an ObjectId?

[{
    "$lookup": {
        "from": "videos",
        "localField": "items",
        "foreignField": "_id",
        "as": "appendedItems"
    }
}]

推荐答案

在mongodb 3.2版中,无法在$ lookup中将字符串与ObjectId进行匹配,为此问题打开了一些票证,您可以关注这些问题,并且为他们投票.

It is not possible to match string with ObjectId in $lookup in mongodb version 3.2, there are some tickets opened for this issue, you can follow these issue and also vote for them.

https://jira.mongodb.org/browse/SERVER-22781

https://jira.mongodb.org/browse/SERVER-24947

这篇关于猫鼬$ lookup,其中localField是foreignField中ObjectId的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆