當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Collection.insertOne方法代碼示例

本文整理匯總了TypeScript中mongodb.Collection.insertOne方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Collection.insertOne方法的具體用法?TypeScript Collection.insertOne怎麽用?TypeScript Collection.insertOne使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mongodb.Collection的用法示例。


在下文中一共展示了Collection.insertOne方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: resolve

 return new Promise<ObjectID>((resolve, reject) => {
   this._collection.insertOne(user).then((result) => {
     resolve(result.insertedId)
   }).catch((err) => {
     reject(new Error('Could not insert user: ' + err.message))
   })
 })
開發者ID:TechNottingham,項目名稱:Hack24-API,代碼行數:7,代碼來源:users.ts

示例2: resolve

 return new Promise<ObjectID>((resolve, reject) => {
   this._collection.insertOne(hack).then(() => {
     resolve()
   }).catch((err) => {
     reject(new Error('Could not insert hack: ' + err.message))
   })
 })
開發者ID:TechNottingham,項目名稱:Hack24-API,代碼行數:7,代碼來源:hacks.ts

示例3:

 Promise.all(updates.map(update => {
     if (update.method === 'add') {
         return col.insertOne(update.racer);
     } else {
         return col.deleteOne({id: update.id});
     }
 })).then(() => process.send('update'));
開發者ID:Tiedye,項目名稱:RazzieTest,代碼行數:7,代碼來源:stress-test-racer.ts

示例4: resolve

 return new Promise<Attendee>((resolve, reject) => {
   this._collection.insertOne(randomAttendee).then((result) => {
     randomAttendee._id = result.insertedId
     resolve(randomAttendee)
   }).catch((err) => {
     reject(new Error('Could not insert random attendee: ' + err.message))
   })
 })
開發者ID:TechNottingham,項目名稱:Hack24-API,代碼行數:8,代碼來源:attendees.ts

示例5: add

 public async add(schedule: ScheduledEvent): Promise<void> {
     await this.collection.insertOne({
         token: schedule.token,
         timestamp: schedule.timestamp,
         event: this.serializer.serialize(schedule.event),
         eventType: schedule.event.fullyQualifiedName
     });
 }
開發者ID:martyn82,項目名稱:aphajs,代碼行數:8,代碼來源:MongoDbScheduleStorage.ts

示例6: Date

			return this.dbExecute<TEntity>((collection: Collection, subject: Subject<TEntity>) => {
				entity.lastUpdated = entity.createdDate = new Date();
				collection.insertOne(entity, (err: WriteError, result: InsertOneWriteOpResult) => {
					if (err) {
						throw new Error(err.errmsg);
					}

					entity._id = result.insertedId.toHexString();
					subject.next(entity);
					subject.complete();
				});
			});
開發者ID:nickmorton,項目名稱:yes-admin,代碼行數:12,代碼來源:repository-base.ts

示例7:

 Observable.fromPromise<number>(this.historyCollection.count({username: username})).subscribe(count => {
     if (count == 0) {
         Observable.fromPromise<InsertOneWriteOpResult>(this.historyCollection.insertOne({username: username, days: [dayInfo]})).subscribe(() => {
             console.log("Finished creating");
             observer.onNext("sup")
         });
     } else {
         Observable.fromPromise<any>(this.historyCollection.findOneAndUpdate({username: username}, { $push: {days: dayInfo}})).subscribe(() => {
             console.log("Finished inserting");
             observer.onNext(true);
         });
     }
 });
開發者ID:Kattoor,項目名稱:Uninova,代碼行數:13,代碼來源:userManager.ts

示例8: insert

 public async insert(
     sagaClass: string,
     id: string,
     associationValues: AssociationValueDescriptor,
     data: string
 ): Promise<void> {
     await this.collection.insertOne({
         id: id,
         sagaClass: sagaClass,
         payload: data,
         associationValues: associationValues
     });
 }
開發者ID:martyn82,項目名稱:aphajs,代碼行數:13,代碼來源:MongoDbSagaStorage.ts


注:本文中的mongodb.Collection.insertOne方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。