本文整理汇总了TypeScript中mongodb.MongoClient类的典型用法代码示例。如果您正苦于以下问题:TypeScript MongoClient类的具体用法?TypeScript MongoClient怎么用?TypeScript MongoClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MongoClient类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: Promise
var p1 = new Promise(function(resolve, reject){
mongodb.MongoClient.connect(url, (err, db) => {
if (!err) {
DB = db;
resolve(DB);
}
else {
reject(err);
}
});
});
开发者ID:bernardius,项目名称:expressts,代码行数:11,代码来源:mongo-utils.ts
示例2: connect
public async connect() {
const options = mongodbUri.parse(config.MONGODB_URI);
const uri = mongodbUri.format(options);
const connection = await MongoClient.connect(uri, {
useNewUrlParser: true,
});
this.database = connection.db(options.database);
// tslint:disable-next-line
console.log("Connected to DB...");
return this.database;
}
开发者ID:vnenkpet,项目名称:japanese,代码行数:11,代码来源:db.ts
示例3: addTweets
addTweets(tweets){
MongoClient.connect(url, tweets, function (err, db) {
assert.equal(null, err);
console.log("Connected correctly to server.");
assert.equal(null, err);
this.insertDocuments(db, tweets, function () {
db.close();
});
});
}
开发者ID:bmtwebdevs,项目名称:tweetchildofmine,代码行数:11,代码来源:repository.ts
示例4: connect
function connect(callback: (err, db) => void) {
var url = 'mongodb://'
+ (process.env.OPENSHIFT_MONGODB_DB_USERNAME != null
? process.env.OPENSHIFT_MONGODB_DB_USERNAME + ':'
+ process.env.OPENSHIFT_MONGODB_DB_PASSWORD + '@'
: '')
+ (process.env.OPENSHIFT_MONGODB_DB_HOST || '127.0.0.1') + ':'
+ (process.env.OPENSHIFT_MONGODB_DB_PORT || '27017') + '/'
+ 'minesweeper';
MongoClient.connect(url, callback);
}
开发者ID:progre,项目名称:minesweeper,代码行数:11,代码来源:database.ts
示例5: createCard
createCard(card: Card, callback: (c: Card) => any) {
this._client.connect(DaoConstants.CONNECTION_URL, (err:any, db:Db) => {
db.collection('cards').insertOne(card, (err: MongoError, result: InsertOneWriteOpResult) => {
card._id = result.insertedId.toString();
db.close();
callback(card);
});
});
}
开发者ID:biwin,项目名称:KandoeGroepJWebAndBackend,代码行数:11,代码来源:themeDao.ts
示例6: createTheme
createTheme(t: Theme, callback: (theme: Theme) => any) {
this._client.connect(DaoConstants.CONNECTION_URL, (err: any, db: Db) => {
db.collection('themes').insertOne(t, (err: MongoError, result: InsertOneWriteOpResult) => {
t._id = result.insertedId.toString();
db.close();
callback(t);
});
});
}
开发者ID:biwin,项目名称:KandoeGroepJWebAndBackend,代码行数:11,代码来源:themeDao.ts
示例7: addSubThemeToTheme
addSubThemeToTheme(parentThemeId: string, childId: string, callback:(b: boolean) => any) {
this._client.connect(DaoConstants.CONNECTION_URL, (err: any, db: Db) => {
db.collection('themes').updateOne({'_id': new ObjectID(parentThemeId)}, {
$push: {'_subThemes': childId}
}, (err:MongoError, result) => {
db.close();
callback(result.modifiedCount == 1);
});
});
}
开发者ID:biwin,项目名称:KandoeGroepJWebAndBackend,代码行数:11,代码来源:themeDao.ts
示例8: removeAllUsersFromOrganisationById
removeAllUsersFromOrganisationById(organisationId: string, callback: (removed: boolean) => any) {
this.client.connect(DaoConstants.CONNECTION_URL, (err: any, db: Db) => {
db.collection('users').updateMany({'_organisatorOf': {'$in': [organisationId]}}, {$pull: {'_organisatorOf': organisationId}}, (error: MongoError, result: UpdateWriteOpResult) => {
db.collection('users').updateMany({'_memberOf': {'$in': [organisationId]}}, {$pull: {'_memberOf': organisationId}}, (error2: MongoError, result2: UpdateWriteOpResult) => {
db.close();
callback(result.modifiedCount == result.matchedCount && result2.modifiedCount == result2.matchedCount);
});
});
});
}
开发者ID:biwin,项目名称:KandoeGroepJWebAndBackend,代码行数:11,代码来源:userDao.ts
示例9: getAllOrganisationIdsOfUserById
getAllOrganisationIdsOfUserById(userId: string, callback: (organisationIds: string[]) => any) {
this._client.connect(DaoConstants.CONNECTION_URL, (err: any, db: Db) => {
db.collection('organisations').find({'$or': [{'_organisatorIds': {'$in': [userId]}}, {'_memberIds': {'$in': [userId]}}]}).project({'_id': 1}).toArray((err: MongoError, docs: Organisation[]) => {
var ids: string[] = docs.map( o => o._id.toString());
db.close();
callback(ids);
});
});
}
开发者ID:biwin,项目名称:KandoeGroepJWebAndBackend,代码行数:11,代码来源:organisationDao.ts
示例10: connect
public connect(): Observable<Db> {
var observable: Observable<Db> = Observable.fromPromise<Db>(this.mongoClient.connect(this.url));
observable.subscribe(
(db: Db) => {
this.db = db;
this.userCollection = db.collection("users");
this.historyCollection = db.collection("history");
}
);
return observable;
}
开发者ID:Kattoor,项目名称:Uninova,代码行数:11,代码来源:userManager-old.ts
注:本文中的mongodb.MongoClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论