Silences warnings from mongodb client (#5025)

* Silences warnings from mongodb client

* Update count, delete and finds to recommended implementations

* With new parser, readPref will be null by default

* Update flaky specs wih async/await style

* Adds gridstore adapter spec

* Use GridFSBucketStorage adapter
This commit is contained in:
Florent Vilmart
2018-09-04 16:15:09 -04:00
committed by GitHub
parent d83a0b6808
commit a42101531a
14 changed files with 265 additions and 109 deletions

View File

@@ -80,7 +80,7 @@ export default class MongoCollection {
}
count(query, { skip, limit, sort, maxTimeMS, readPreference } = {}) {
const countOperation = this._mongoCollection.count(query, {
const countOperation = this._mongoCollection.countDocuments(query, {
skip,
limit,
sort,
@@ -109,7 +109,7 @@ export default class MongoCollection {
// If there is nothing that matches the query - does insert
// Postgres Note: `INSERT ... ON CONFLICT UPDATE` that is available since 9.5.
upsertOne(query, update) {
return this._mongoCollection.update(query, update, { upsert: true });
return this._mongoCollection.updateOne(query, update, { upsert: true });
}
updateOne(query, update) {
@@ -126,7 +126,7 @@ export default class MongoCollection {
_ensureSparseUniqueIndexInBackground(indexRequest) {
return new Promise((resolve, reject) => {
this._mongoCollection.ensureIndex(
this._mongoCollection.createIndex(
indexRequest,
{ unique: true, background: true, sparse: true },
error => {

View File

@@ -135,6 +135,7 @@ export class MongoStorageAdapter implements StorageAdapter {
this._uri = uri;
this._collectionPrefix = collectionPrefix;
this._mongoOptions = mongoOptions;
this._mongoOptions.useNewUrlParser = true;
// MaxTimeMS is not a global MongoDB client option, it is applied per operation.
this._maxTimeMS = mongoOptions.maxTimeMS;
@@ -385,7 +386,7 @@ export class MongoStorageAdapter implements StorageAdapter {
return storageAdapterAllCollections(this).then(collections =>
Promise.all(
collections.map(
collection => (fast ? collection.remove({}) : collection.drop())
collection => (fast ? collection.deleteMany({}) : collection.drop())
)
)
);
@@ -557,8 +558,8 @@ export class MongoStorageAdapter implements StorageAdapter {
const mongoWhere = transformWhere(className, query, schema);
return this._adaptiveCollection(className)
.then(collection =>
collection._mongoCollection.findAndModify(mongoWhere, [], mongoUpdate, {
new: true,
collection._mongoCollection.findOneAndUpdate(mongoWhere, mongoUpdate, {
returnOriginal: false,
})
)
.then(result => mongoObjectToParseObject(className, result.value, schema))