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