mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-03 19:42:27 +08:00
* Mongodb client.connect options v2.2 * Mongodb::dt-header typescript v2.0 -> v2.3 Read more on typescript ``object`` [type](https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/release%20notes/TypeScript%202.2.md#object-type) * Fix trailing ' mark * Ttravis errors,mongodb: downgrade TS version to 2.2 * Merge SocketOptions into MongoClientOptions * Urgent fix MongoDB.connect() options Most common SSL options now gathered in one place in SSLOptions interface. SSLOptions and newly added HighAvailabilityOptions interface are shared by ServerOptions, MongosOptions and ReplSetOptions interfaces respectively SocketOptions extends SSLOptions. Updates ReadPreference interface to v2.2 Updates docs links. * Restore formatting style * SocketOptions, ServerOptions & ReplSetOptions SocketOptions Removes extension of SSL- and HighAvailability- Options ServerOptions Adds missing options ReplSetOptions Adds missing extensions of SSL- and HighAvailability- Options
95 lines
3.2 KiB
TypeScript
95 lines
3.2 KiB
TypeScript
// Test source : https://github.com/mongodb/node-mongodb-native
|
|
import mongodb = require('mongodb');
|
|
var MongoClient = mongodb.MongoClient;
|
|
|
|
var format = require('util').format;
|
|
let options = {
|
|
authSource : ' ',
|
|
w : 1,
|
|
wtimeout : 300,
|
|
j : true,
|
|
bufferMaxEntries : 1000,
|
|
readPreference : 'ReadPreference | string',
|
|
promoteValues : {},
|
|
pkFactory : {},
|
|
poolSize : 1,
|
|
|
|
socketOptions : {},
|
|
|
|
reconnectTries : 123456,
|
|
reconnectInterval : 123456,
|
|
|
|
ssl : true,
|
|
sslValidate : {},
|
|
checkServerIdentity : function (){ },
|
|
sslCA : ['str'],
|
|
sslCert : new Buffer(999),
|
|
sslKey : new Buffer(999),
|
|
sslPass : new Buffer(999)
|
|
}
|
|
MongoClient.connect('mongodb://127.0.0.1:27017/test', options, function(err: mongodb.MongoError, db: mongodb.Db) {
|
|
if (err) throw err;
|
|
|
|
var collection = db.collection('test_insert');
|
|
collection.insertOne({ a: 2 }, function(err: mongodb.MongoError, docs: any) {
|
|
|
|
collection.count(function(err: mongodb.MongoError, count: any) {
|
|
console.log(format("count = %s", count));
|
|
});
|
|
|
|
// Locate all the entries using find
|
|
collection.find({}).toArray(function(err: mongodb.MongoError, results: any) {
|
|
console.dir(results);
|
|
// Let's close the db
|
|
db.close();
|
|
});
|
|
|
|
// Get some statistics
|
|
collection.stats(function(err: mongodb.MongoError, stats: any) {
|
|
console.log(stats.count + " documents");
|
|
});
|
|
|
|
collection.createIndex({}, {partialFilterExpression: {rating: {$exists: 1}}})
|
|
});
|
|
|
|
{
|
|
let cursor: mongodb.Cursor <any>;
|
|
cursor = collection.find();
|
|
cursor = cursor.addCursorFlag('',true);
|
|
cursor = cursor.addQueryModifier('',true);
|
|
cursor = cursor.batchSize(1);
|
|
cursor = cursor.comment('');
|
|
cursor = cursor.filter(1);
|
|
cursor = cursor.hint({});
|
|
cursor = cursor.limit(1);
|
|
cursor = cursor.map(function (result) {});
|
|
cursor = cursor.max(1);
|
|
cursor = cursor.min(1);
|
|
cursor = cursor.maxAwaitTimeMS(1);
|
|
cursor = cursor.maxScan({});
|
|
cursor = cursor.maxTimeMS(1);
|
|
cursor = cursor.project({});
|
|
cursor = cursor.returnKey({});
|
|
cursor = cursor.setCursorOption('',{});
|
|
cursor = cursor.setReadPreference('');
|
|
cursor = cursor.showRecordId({});
|
|
cursor = cursor.skip(1);
|
|
cursor = cursor.snapshot({});
|
|
cursor = cursor.sort({});
|
|
cursor = cursor.stream();
|
|
}
|
|
// Collection .findM<T>() & .agggregate<T>() generic tests
|
|
{
|
|
let bag : {cost: number, color: string};
|
|
type bag = typeof bag;
|
|
let cursor: mongodb.Cursor<bag> = collection.find<bag>({color: 'black'})
|
|
cursor.toArray(function (err,r) { r[0].cost} );
|
|
cursor.forEach(function (bag ) { bag.color }, () => {});
|
|
}
|
|
{
|
|
let payment: {total: number};
|
|
type payment = typeof payment;
|
|
let cursor: mongodb.AggregationCursor<payment> = collection.aggregate<payment>([{}])
|
|
}
|
|
})
|