本文整理匯總了TypeScript中mongodb.ObjectId類的典型用法代碼示例。如果您正苦於以下問題:TypeScript ObjectId類的具體用法?TypeScript ObjectId怎麽用?TypeScript ObjectId使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ObjectId類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should return the raw transform object if options field exists and set to true', () => {
let id = new ObjectId();
let coin = {
_id: id,
network: 'regtest',
chain: 'BTC',
mintTxid: '81f24ac62a6ffb634b74e6278997f0788f3c64e844453f8831d2a526dc3ecb13',
mintIndex: 0,
mintHeight: 1,
coinbase: true,
value: 5000000000.0,
address: 'n1ojJtS98D2VRLcTkaHH4YXLG4ytCyS7AL',
script: Buffer.from(''),
wallets: [],
spentTxid: '',
spentHeight: SpentHeightIndicators.unspent
} as ICoin;
const result = CoinStorage._apiTransform(coin, { object: true });
expect(result).to.deep.equal({
_id: id.toHexString(),
mintTxid: '81f24ac62a6ffb634b74e6278997f0788f3c64e844453f8831d2a526dc3ecb13',
network: 'regtest',
chain: 'BTC',
spentTxid: '',
mintHeight: 1,
mintIndex: 0,
spentHeight: SpentHeightIndicators.unspent,
address: 'n1ojJtS98D2VRLcTkaHH4YXLG4ytCyS7AL',
coinbase: true,
confirmations: -1,
script: '',
value: 5000000000.0
});
});
示例2: validateId
static validateId(id: any): boolean {
return ObjectId.isValid(id);
}
示例3: stringifyId
static stringifyId(id: ObjectId): string {
return id.toHexString();
}