mongoose-populate

Mongoose Populate not working with Array of ObjectIds

狂风中的少年 提交于 2019-12-11 03:02:34
问题 Here is my schema: /** Schemas */ var profile = Schema({ EmailAddress: String, FirstName: String, LastName: String, BusinessName: String }); var convSchema = Schema({ name: String, users: [{ type: Schema.Types.ObjectId, ref: 'Profiles' }], conversationType: { type: String, enum: ['single', 'group'], default: 'single' }, created: { type: Date, default: Date.now }, lastUpdated: { type: Date, default: Date.now } }); /** Models */ db.Profiles = mongoose.model('Profiles', profile); db

Mongoosejs virtual populate

时光总嘲笑我的痴心妄想 提交于 2019-12-10 02:13:43
问题 I have a circle model in my project: var circleSchema = new Schema({ //circleId: {type: String, unique: true, required: true}, patientID: {type: Schema.Types.ObjectId, ref: "patient"}, circleName: String, caregivers: [{type: Schema.Types.ObjectId}], accessLevel: Schema.Types.Mixed }); circleSchema.virtual('caregiver_details',{ ref: 'caregiver', localField: 'caregivers', foreignField: 'userId' }); caregiver schema: var cargiverSchema = new Schema({ userId: {type: Schema.ObjectId, unique: true}

Mongoose: Filter collection based on values in another collection

扶醉桌前 提交于 2019-12-08 08:41:30
Consider documents that contain an arrays of ID of another collection, how can I find documents applying a filter based on the related collection using mongoose? I can't find my error Installation.aggregate( [ // Stage 1 { $lookup: { from: "users", localField: "_id", foreignField: "_id", as: "Users" } }, // Stage 2 { $unwind: { path: "$Users" } }, // Stage 3 { $match: {"Users.Email1" : "test@test.com"} }, { $sort: { _id: -1 } }, { $limit: 10 } ] ,function (err, installations) { console.log(installations); //<<<<< Empty /* Installation.populate( 'Parent', '_id Email1','Company'), function(err

Are there ways to populate a schema in Joi from another schema (like Mongoose does)?

时光毁灭记忆、已成空白 提交于 2019-12-08 03:38:17
问题 I'm currently only using Joi to validate and building schemas. However I feel like I'm missing features like reference another schema like Mongoose does. Or is the only way to do this by using both (or mongoose only)? I want to use something similar to this: const mongoose = require('mongoose'); const Schema = mongoose.Schema; const personSchema = Schema({ _id: Schema.Types.ObjectId, name: String, age: Number, stories: [{ type: Schema.Types.ObjectId, ref: 'Story' }] }); const storySchema =

Are there ways to populate a schema in Joi from another schema (like Mongoose does)?

安稳与你 提交于 2019-12-06 15:35:16
I'm currently only using Joi to validate and building schemas. However I feel like I'm missing features like reference another schema like Mongoose does. Or is the only way to do this by using both (or mongoose only)? I want to use something similar to this: const mongoose = require('mongoose'); const Schema = mongoose.Schema; const personSchema = Schema({ _id: Schema.Types.ObjectId, name: String, age: Number, stories: [{ type: Schema.Types.ObjectId, ref: 'Story' }] }); const storySchema = Schema({ author: { type: Schema.Types.ObjectId, ref: 'Person' }, title: String, fans: [{ type: Schema

Mongoosejs virtual populate

社会主义新天地 提交于 2019-12-05 01:47:49
I have a circle model in my project: var circleSchema = new Schema({ //circleId: {type: String, unique: true, required: true}, patientID: {type: Schema.Types.ObjectId, ref: "patient"}, circleName: String, caregivers: [{type: Schema.Types.ObjectId}], accessLevel: Schema.Types.Mixed }); circleSchema.virtual('caregiver_details',{ ref: 'caregiver', localField: 'caregivers', foreignField: 'userId' }); caregiver schema: var cargiverSchema = new Schema({ userId: {type: Schema.ObjectId, unique: true}, //objectId of user document detailId: {type: Schema.ObjectId, ref: "contactDetails"}, facialId: {type

How to remove object taking into account references in Mongoose Node.js?

与世无争的帅哥 提交于 2019-12-03 22:53:36
问题 This is my MongoDB schema: var partnerSchema = new mongoose.Schema({ name: String, products: [ { type: mongoose.Schema.Types.ObjectId, ref: 'Product' }] }); var productSchema = new mongoose.Schema({ name: String, campaign: [ { type: mongoose.Schema.Types.ObjectId, ref: 'Campaign' } ] }); var campaignSchema = new mongoose.Schema({ name: String, }); module.exports = { Partner: mongoose.model('Partner', partnerSchema), Product: mongoose.model('Product', productSchema), Campaign: mongoose.model(

Mongoose connect two collections

浪尽此生 提交于 2019-12-02 10:58:48
I have a collection of products, and another on the reposition of stock of the product. What I'm looking for is that when I get the products, all the replenishment dates and the new stock appear, something like this: { "ok": true, "producto": { "repo": [ { "_id": "5ac643ab88b5a132384f7758", "restock": 22, "date": "2018-03-04T03:00:00.000Z", "producto": "5ac6433588b5a132384f7757", "__v": 0 }, { "_id": "5ac6470079b67f39985ffe3c", "restock": 44, "date": "2018-04-04T03:00:00.000Z", "producto": "5ac6433588b5a132384f7757", "__v": 0 } ], "_id": "5ac6433588b5a132384f7757", "nombre": "Vianda

populate nested array of nested ref

流过昼夜 提交于 2019-12-02 10:05:59
The structure of the project is structure The main file is index.js that is located in the main directory. This one has 'use strict' var mongoose = require('mongoose'); var app = require('./app'); var port = process.env.port || 3000; mongoose.connect('mongodb://localhost:27017/changeProducts',(err,res) =>{ if(err){ throw err; }else{ console.log("Base de datos funcionando correctamente.."); app.listen(port, function(){ console.log('Servidor nodejs corriendo(app.listen)... '); }); } }); The version of mongoose is 5.0 The app.js is 'use strict' var express = require('express'); var bodyParser =

The correct syntax for sorting mongoose 3.x populated document

巧了我就是萌 提交于 2019-11-30 21:20:47
问题 I have two MongoDB collections Customer and User in 1:1 relationship. I'm trying to query both documents using Mongoose Population and sort them by User.name . Nothing below is working. My Mongoose is 3.8.19. Customer .find({}) .populate("user", "name email phone") .sort({ "name": 1 }) .exec() Customer .find({}) .populate("user", "name email phone", null, { sort: { 'name': 1 } } ) .exec() Customer .find({}) .populate({ path: "user", select: "name email phone", options: { sort: { "name": 1 }}