Tag: populate

如何使用Mongoose将多个参考文件保存到MongoDB中的其他文档?

我正在试图找出如何使用Mongoose在MongoDB中保存多个对其他文档的引用。 将一个引用保存到其他文档并不是什么大事,但是当您要将多个引用保存到其他文档并在稍后填充时,它会变得很复杂。 让我们看看我有什么: var mongoose = require('mongoose'), Schema = mongoose.Schema; var Book = Schema({ title: String, reviews: [{ type: Schema.Types.ObjectId, ref: 'Review' }] }); var Review = Schema({ body: String }); var Book = mongoose.model('Book', bookSchema); var Review = mongoose.model('Book', reviewSchema); var reviewItem = new Review({body: "review content"}); Book.find({}).exec(function(err, collection) { if(collection.length === 0) { […]

无法使用mongoosejs进行填充

为什么我不能得到结果,而试图填充我的计划(我使用mongoosejs)。 在我的情况下,我的类别,子类别,sububcategoryscheme不使用_id。 我使用自定义ID。 这是我的产品scheme: ….. categoryId: { type: String, ref: 'Catgory', required: true }, subcategoryId: { type: String, ref: 'Subcategory', required: true }, subsubcategoryId: { type: String, ref: 'Subsubcategory', required: true }); const Product = mongoose.model('Product', product); module.exports = Product; 这是我的产品控制器: 'getOne': function(req, res, next) { if (typeof req.params.id !== 'string') return res.send({ 'error-code': 3 […]

在MongoDB中用mongoose批量插入多个集合

我有2个集合( data ,元data ) data模式是 { _id: ……, name: ……, //not unique mobile: ……, // unique or null email: ……, // unique or null uniqueId: ……, // unique or null } 插入需要至less一个唯一的数据 metaData模式是 { _id: ……, dataId: ……,//refrence from _id of data collection key: ……, value: …… } JSON数组正在从客户端获得 [{ name: "abc", mobile: 9999999999, mData: […]

如何注册和使用mongoose深入

好的。 所以我试图做一些我的mongoose模型的嵌套人口。 而且我发现Mongoose-Deep-Populate是嵌套解决scheme的最简单的修复之一,但是,看起来很简单,我不知道如何正确注册插件。 我正在使用angular-fullstack项目,只是添加了deep-populate插件的npm install 。 然后我进入我的模型,并添加了这个: 'use strict'; var deepPopulate = require('mongoose-deep-populate'); var mongoose = require('mongoose'), Schema = mongoose.Schema; var EntrySchema = new Schema({ articleId: Number, title: String, content: String, date: Date, children: [{ type: Schema.ObjectId, ref: 'Entry' }], forum: { type: Schema.ObjectId, ref: 'Forum' }, language: { type: Schema.ObjectId, ref: 'Language' }, orphan: […]