本文整理匯總了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;
}