2017-11-28 12 views
0

私は2つのモデルを持っており、顧客モデルの各IDの状態をステータスモデルから探したいのですが、ここで集計を使用していますが、誰でも助けてください.............................................mongoose集約が空の配列を返す

///顧客モデル

///テーブル名は、データベース内のcrmcustomersある

var mongoose = require('mongoose'); 
var Schema = mongoose.Schema; 

var schemaOptions = { 
    timestamps: true, 
    toJSON: { 
     virtuals: true 
    } 
}; 

var CrmCustomerSchema = new Schema({ 
    name: String, 
    shop_name: String, 
    address: String, 
    phone: { type: String, unique: true}, 
    comment: String, 
    email: String, 
    website : String, 
    interest: String, 
    reference : String, 



    }, schemaOptions); 


    var CrmCustomer = mongoose.model('CrmCustomer', CrmCustomerSchema); 

    module.exports = CrmCustomer; 

///ステータスモデル

///テーブル名210

は、クエリ

CrmCustomer.aggregate([ 

     { 
      "$lookup": { 
       "from": "crmcustomerstatus", 
       "localField": "_id", 
       "foreignField": "crm_id", 
       "as": "result" 
      } 
     }, 

    ]).exec(function(err, results){ 
     console.log(results); 
    }) 

///は空の結果を取得するための

[ { _id: 5a1cf755b5268904a476c7d2, 
    updatedAt: 2017-11-28T05:42:45.239Z, 
    createdAt: 2017-11-28T05:42:45.239Z, 
    name: 'istiaque ahmad', 
    shop_name: 'les mecaron', 
    address: 'mirpur', 
    phone: '01764199657', 
    email: '[email protected]', 
    website: 'xccxxxxx', 
    comment: 'dsfsdf', 
    interest: 'dsfsdf', 
    reference: 'dsfsdfsdf', 
    __v: 0, 
    result: [] } ] 

答えて

0

理由はCrmCustomer_idある結果////

var mongoose = require('mongoose'); 
var Schema = mongoose.Schema; 

    var schemaOptions = { 
     timestamps: true, 
     toJSON: { 
      virtuals: true 
     } 
    }; 

var CrmCustomerStatusSchema = new Schema({ 
crm_id : String, 
name: String, 
shop_name : String, 
status : String 

}, schemaOptions); 

var CrmCustomerStatus = mongoose.model('CrmCustomerStatus', CrmCustomerStatusSchema); 

module.exports = CrmCustomerStatus; 

データベースにcrmcustomerstatusesありますスキーマはObjectIdの型ですが、crm_idCrmCustomerStatusスキーマは文字列

です。

変更されたCrmCustomerStatusスキーマ

var CrmCustomerStatusSchema = new Schema({ 
crm_id : ObjectId, 
name: String, 
shop_name : String, 
status : String 
関連する問題