2016-06-03 5 views
-1

ts 파일에 모델을 정의했습니다. 해당 모델과 관련된 특정 몽구스 연결 (기본 연결이 아님)을 사용하고 싶습니다. 모델을 연결에 연결하려면 어떻게해야합니까? 내 server.ts 파일에서몽구스와 Typescript - 특정 몽구스 연결로 모델 연결

export interface iSuppliers extends mongoose.Document { 
suppliers: string[]; 
fields: number[]; 
} 

export const supplierSchema = new mongoose.Schema({ 
    suppliers: {type:[String], required: true}, 
    fields: [Number]}) 
.index({suppliers: 1}); // Additional index 

export const supplier = mongoose.model<iSuppliers>('supplier', supplierSchema); 

: 내가 데이터를 찾을 수 내 공급 업체 모델을 사용하는 경우

import {supplier} from '....'; 
.... 
let database_2 = mongoose.createConnection(....); 

아무런 변화가 없습니다

발췌 내 TS 파일을 형성한다. 는 분명히, 나는

내가 수출 ... 나는 내 길을 발견

+0

정교한 비트를 자세히 설명해 주시겠습니까? –

+0

자세한 내용으로 내 의견을 편집했습니다 ... – 3Pi

+1

[몽구스로 2 개의 다른 모델 세트와 2 개의 연결 방법은 무엇입니까?] (http://stackoverflow.com/questions/12937883/how-to-have- 2 연결 -2 다른 모델 세트와 함께 - 몽구스) – cdbajorin

답변

0

....

내가 그것과 방식에 대해 잘 모르겠습니다 ... 내 database_2 연결에 바인딩 할 필요가 모델을 반환하고 매개 변수로 내 연결을 사용하는 함수입니다 ...

export function importedGameDatabase(mongooseConnection: mongoose.connection) { return mongooseConnection.model<iImportedGames>('importedGame', importedGamesSchema); }