-
0 votesanswersviews
试图在mongoose中填充嵌套数组,抛出看似无关的CastError,我无法理解为什么
我是mongoose的新手,我正在尝试一些非常基本的参考和模式实验 . 我要做的是拥有一个“安装”实体,其中包含按类型分组的设备数组 . 在这个组的内部,有一组引用的单个设备的id . 我的架构是这样的: ///INSTALLATIONS.js var installationSchema = mongoose.Schema({ _id: Number, devices: [dev... -
0 votesanswersviews
mongoose自带填充自定义查询
我正在尝试在mongoose中创建一个自定义查询方法 - 类似于populate() - mongoose的功能 . 我有以下两个简单的模式: const mongoose = require('mongoose') const bookSchema = new mongoose.Schema({ title: String, author: {type: mongoose.Sc... -
0 votesanswersviews
为什么我会为以下mongooseJS架构收到转换错误?
尝试测试架构时出现以下错误: “CastError:Cast to ObjectId for value”{by:58803a77479f7e2a2d069d93,at:2017-01-19T04:03:03.156Z}“at path”_id“for model”Poll“ const PollSchema = Schema({ title: { type: String, re... -
1 votesanswersviews
.populate在非必需的领域mongoose
我试图在非强制字段上使用populate可能与其他集合有关系,或者可能是空白的,当我尝试填充该字段时,它会给出错误 “转换为ObjectId失败的值”“路径”_id“” 码: Paper.find(query).populate('1').populate('2').populate('3').exec(cb) 现在纸质文件中的3_id可能是空白的 . 架构就像 var paper_schema ... -
0 votesanswersviews
猫鼬深深地生长
我有两个架构, 一个用于用户,另一个用于发布 在用户模式中,我有一个latestPost的属性,它可以是post模式中条目的ObjectId 当我加载用户对象时, 我想将lastestPost作为一个对象,包括作者用户模式中的用户名,其中作者是一个与用户模式中的_id字段匹配的ObjectId . mongoose教程似乎使用了语法 User.findOne({ _id: req.user.id}... -
1 votesanswersviews
只有当字段包含ObjectId时,是否可以让mongoose填充混合字段?
设置 假设我们有 Foo 和 Bar 的模式 . Foo 有一个字段 bar . 此字段可以包含引用文档 Bar 的ObjectId,也可以包含不是ObjectIds的其他任意对象 . const fooSchema = new mongoose.Schema({ bar: { type: mongoose.Schema.Types.Mixed, ref: 'Bar' ... -
1 votesanswersviews
Mongoose嵌套/深填充
我知道很多次都会问这个问题,但我对mongodb / mongoose有点新意见!目前我正在研究用于医疗软件的MEAN堆栈 . 以下是我的架构: var usersSchema = new Schema({ _id : {type : mongoose.Schema.ObjectId} //... }); mongoose.model('Users', usersSchema... -
11 votesanswersviews
单个模式数组中的多个模式引用 - mongoose
您是否可以在mongoose模式中使用对几个不同模式选项的引用来填充数组? 为了澄清这个问题,请说我有以下模式: var scenarioSchema = Schema({ _id : Number, name : String, guns : [] }); var ak47 = Schema({ _id : Number //Bunch of AK s... -
0 votesanswersviews
使用nodejs在mongoose模式中的数组中添加值
我正在开发一个在线课程申请表 . 我已经为课程注册创建了一个集合,我将存储课程名称和在该课程中注册的用户 . Mongoose模式看起来像这样 . 它的名字是courseEnrollment.js . var mongoose = require('mongoose'); var Schema = mongoose.Schema; var courseEnrollment = new Sche... -
1 votesanswersviews
填充Mongoose中子模式的聚合结果
我有以下(简化)架构 var options = {discriminatorKey:'kind'}; var activitySchema = new Schema( { title:{type:String} },options ); var Activity = mongoose.model('Activity', activitySchema); var date... -
-1 votesanswersviews
如何使用不同类型的引用和填充
所以我有两个模式,文章和事件都有一个图像字段 . 对于文章, featured_image: { type: String, default: '', } 对于活动, featured_image: { type: Schema.ObjectId, ref: 'Medium' } 我有另一个架构,卡,像这样 type: { type: String, ... -
0 votesanswersviews
Mongoose未参考新保存的文档填充以前保存的文档
所有 . 我正在编写一个MEAN堆栈应用程序,使用Mongoose(4.0.6)与Node / Express连接MongoDB,当我稍后保存现有文档应该引用的新文档时,我遇到了填充已保存文档的困难 . 具体来说,在应用程序中,我让用户在为该公司创建管理员帐户之前创建公司实例,因此当用户将他/她自己注册为管理员时,我希望公司文档用其填充其用户数组新用户 . 以下是我公司和用户的模式: user.j... -
6 votesanswersviews
mongoose:填充一个有区别的子文档
我想填充子文档的字段,该子文档是公共架构的区别元素( Notificationable 被区分为 Message 或 FriendRequest ) . 这个问题与这个问题非常相似:mongoosejs: populating an array of objectId's from different schemas,两年前没有解决 . 既然猫鼬进化了,也有鉴别者,我再问这个问题 . 到目前为止我... -
17 votesanswersviews
Mongoose填充嵌套数组
假设有以下3种型号: var CarSchema = new Schema({ name: {type: String}, partIds: [{type: Schema.Types.ObjectId, ref: 'Part'}], }); var PartSchema = new Schema({ name: {type: String}, otherIds: [{type: ... -
0 votesanswersviews
当refs不存在时填充字段
如果没有存储引用,是否可以通过填充EVEN接收填充的引用列表? 我有这个架构: Person _id,姓名,年龄Comment _id,creator(= Person._id),文字 不幸的是,我只是在阅读数据而不是存储数据 . 存储数据的应用程序不会将refs保存到person-documents中的Comments . 是否仍然可以以填充('comments')的方式定义Person-S... -
0 votesanswersviews
猫鼬填充一个字段
我有两个mongoose架构 var mongoose = require('mongoose'); var Schema = mongoose.Schema; var itemSchema = new Schema({ name: {type: String, required: true, max: 25, trim: true}, price: {type: Numbe... -
1 votesanswersviews
mongoose#populate在数组内的嵌套对象中返回null
我有一个mongoDB数据库,它是使用一个脚本生成的,该脚本只使用没有mongoose的node.js mongoDB驱动程序 . 稍后,在应用程序中,我想使用mongoose加载文档并自动填充引用;然而,这只会返回 null . 想象一个包含子项的任务,每个子项都有一个 Headers 和一个指定的人 . 在这种情况下,分配的人是我想要填充的引用,因此引用存在于任务模式中的数组内的对象中 . ... -
1 votesanswersviews
Mongoose虚拟填充和聚合
我正在尝试对使用较新的虚拟填充功能的Mongoose模式进行聚合(使用Mongoose 4.13,Mongo 3.6) . 假设我有以下(为了说明目的而简化)模式: const ProjectSchema = new mongoose.Schema({ projectId: Number, description: String }); ProjectSchema.virtual('ta... -
0 votesanswersviews
使用Mongoose Virtual架构时,请检查多个字段?
我试图找出在我的数据库中填充虚拟架构的最佳方法,我有点困惑 . 在这种情况下,我想检查多个字段,但我不知道有任何方法可以做到这一点或替代方法 . 我曾希望我可以在虚拟架构的'localField'和'foreignField'键中使用一些字符串数组,但事实并非如此 . 用户已保存“系列”_id,并且虚拟架构“联盟”获得用户进入的所有联赛,该联赛属于不同系列的联赛 . 我想只检索用户输入的联赛并且与... -
1 votesanswersviews
Mongoose:引用来自另一个子文档AND群的子文档
我有一个名为 school 的文档模型,它又有两个子文档: 学生 班 每个学生都属于一个 class . var classSchema = new Schema({ name: {type : String} }); var studentSchema = new Schema({ name : {type : String, required:true}, class: ... -
2 votesanswersviews
Mongoose模型在填充后获得未定义的属性
我遇到了基本请求的问题 . 我获取的mongoose模型的所有属性在exec()回调中都是未定义的 . 这是我的架构: userSchema: new Schema({ email: { type: String, limit: 50, index: true }, password: String, birthdate: { type: Date }, activ... -
0 votesanswersviews
如何使用mongoose按节点在节点中填充结果?
我有2个架构 . 命名用户和朋友 . 用户架构如下: var userSchema = mongoose.Schema({ first_name: {type: String}, last_name: {type: String}, update_at: {type: Date} }) Friends Schema如下: var userfollowersSchema =... -
0 votesanswersviews
如何基于引用键检索模式的其他详细信息
我有一个正在进行的项目 . 我有一个评论架构,喜欢架构和博客架构 . 所有这三个都被声明为单独的模式,但是喜欢和评论模式然后嵌套到博客模式中作为子项,即注释:[CommentSchema] . 现在我有一个页面,当有人点击博客时,它会显示所有评论和博客 . 这个代码获取博客Blog.findById(id).populate('user','username') . exec(function(e... -
0 votesanswersviews
嵌套模式中的Mongoose填充数组
这是我的架构: var userSchema = { folders : [ folderSchema ], ... } var folderSchema = new mongoose.Schema({ itemlist : [{ type: String, ref: 'Item', required: true }], foldername ... -
2 votesanswersviews
使用Mongoose-paginate插件填充多个Mongoose模型字段
我有一个Mongoose Schema(约会),有两个reffield(发送者和接收者) . 两者都引用相同的Schema(用户) . 我试图使用mongoose-paginate插件填充这两个字段 . 约会架构片段 . var paginate = require('mongoose-paginate'); var AppointmentSchema = new Schema({ date... -
1 votesanswersviews
如何从Nodejs中另一个模式内引用的模式中填充mongoose模式值?
我有一个“产品”的猫鼬模式,其中包括一系列颜色(另一种模式) . 订单架构包含用户和产品数组 . 产品包含产品,数量和颜色 . 这里的颜色是特定于产品的模式 . 我希望用户能够订购特定颜色的产品(产品可用的颜色)如何填充所选产品的颜色? 型号\ product.js var mongoose = require('mongoose'), Schema = mongoose.Schema; var... -
1 votesanswersviews
Mongoose填充排序选项
我试图通过填充的字段对填充的文档进行排序,类似于mongoose文档中的示例: http://mongoosejs.com/docs/api.html#query_Query-populate 其中Kitten通过objectId引用所有者,并且可以按所有者名称对Kitten上的查询进行排序 . 我尝试了很多语法变体,例如从中给出的答案 How to sort a populated docume... -
2 votesanswersviews
带有mongoose的typescript:无法读取未定义的属性'CasterConstructor'
我正在使用typescript和mongoose编写node.js应用程序 . 我使用的是打字稿模型方法,当我调用create方法创建一个新的子文档时,继续接收“无法读取未定义的属性CasterConstructor” . 代码示例如下: seat.ts: export let SeatSchema: Schema = new Schema({ travelerId: {type: Sch... -
0 votesanswersviews
如何使用mongoose“populate”来指定不同集合的现有文档的路径?
我正在使用Apollo Graphql,Express-Nodejs,MongoDB和Mongoose . 我有2个集合:商业和订单 . 这是模型 以下是graphql类型: 这是突变: createBusiness( name: String, address: String, ): Business createOrder( orderN...