本文整理汇总了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))
})
})
示例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))
})
})
示例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'));
示例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))
})
})
示例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
});
}
示例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();
});
});
示例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);
});
}
});
示例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
});
}