Skip to content

Commit 946f85c

Browse files
committed
Continued development
1 parent 150b71e commit 946f85c

17 files changed

+244
-534
lines changed

examples/src/main/scala/examples/nodejs/datastores/MongoAggregateExample.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class MongoAggregateExample(bootstrap: Bootstrap) {
3838
collection <- db.collectionFuture("aggregationExample1")
3939

4040
// Insert the docs
41-
writeResults <- collection.insertMany(docs, WriteOptions(w = 1))
41+
writeResults <- collection.insertMany(docs, new WriteOptions(w = 1))
4242

4343
// Execute aggregate, notice the pipeline is expressed as an Array
4444
result <- collection.aggregateFuture[Data](js.Array(

node/mongodb/src/main/scala/com/github/ldaniels528/meansjs/nodejs/mongodb/AggregationCursorOptions.scala

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,7 @@ import scala.scalajs.js.annotation.ScalaJSDefined
55

66
/**
77
* Aggregation Cursor Options
8-
8+
* @param batchSize The batchSize for the cursor
99
*/
1010
@ScalaJSDefined
11-
class AggregationCursorOptions extends js.Object {
12-
/** The batchSize for the cursor */
13-
var batchSize: js.UndefOr[Integer] = _
14-
}
15-
16-
/**
17-
* Aggregation Cursor Options
18-
19-
*/
20-
object AggregationCursorOptions {
21-
22-
def apply(batchSize: js.UndefOr[Integer] = js.undefined) = {
23-
val options = new AggregationCursorOptions()
24-
options.batchSize = batchSize
25-
options
26-
}
27-
28-
}
11+
class AggregationCursorOptions(var batchSize: Integer = null) extends js.Object

node/mongodb/src/main/scala/com/github/ldaniels528/meansjs/nodejs/mongodb/AggregationOptions.scala

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,21 @@ import scala.scalajs.js.annotation.ScalaJSDefined
77

88
/**
99
* Aggregation Options
10-
10+
* @param readPreference The preferred read preference
11+
* @param cursor Return the query as cursor, on 2.6 > it returns as a real cursor on pre 2.6 it
12+
* returns as an emulated cursor.
13+
* @param explain Explain returns the aggregation execution plan (requires mongodb 2.6 >).
14+
* @param allowDiskUse allowDiskUse lets the server know if it can use disk to store temporary results for
15+
* the aggregation (requires mongodb 2.6 >).
16+
* @param maxTimeMS maxTimeMS specifies a cumulative time limit in milliseconds for processing operations
17+
* on the cursor.
18+
* MongoDB interrupts the operation at the earliest following interrupt point.
19+
* @param bypassDocumentValidation Allow driver to bypass schema validation in MongoDB 3.2 or higher.
1120
*/
1221
@ScalaJSDefined
13-
class AggregationOptions extends js.Object {
14-
15-
/**
16-
* The preferred read preference
17-
* @see [[ReadPreference.PRIMARY]]
18-
* @see [[ReadPreference.PRIMARY_PREFERRED]]
19-
* @see [[ReadPreference.SECONDARY]]
20-
* @see [[ReadPreference.SECONDARY_PREFERRED]]
21-
* @see [[ReadPreference.NEAREST]]
22-
*/
23-
var readPreference: js.UndefOr[ReadPreference] = _
24-
25-
/** Return the query as cursor, on 2.6 > it returns as a real cursor on pre 2.6 it returns as an emulated cursor. */
26-
var cursor: js.UndefOr[AggregationCursorOptions] = _
27-
28-
/** Explain returns the aggregation execution plan (requires mongodb 2.6 >). */
29-
var explain: js.UndefOr[JBoolean] = _
30-
31-
/** allowDiskUse lets the server know if it can use disk to store temporary results for the aggregation (requires mongodb 2.6 >). */
32-
var allowDiskUse: js.UndefOr[JBoolean] = _
33-
34-
/** maxTimeMS specifies a cumulative time limit in milliseconds for processing operations on the cursor.
35-
* MongoDB interrupts the operation at the earliest following interrupt point. */
36-
var maxTimeMS: js.UndefOr[Integer] = _
37-
38-
/** Allow driver to bypass schema validation in MongoDB 3.2 or higher. */
39-
var bypassDocumentValidation: js.UndefOr[JBoolean] = _
40-
41-
}
42-
43-
/**
44-
* Aggregation Options
45-
46-
*/
47-
object AggregationOptions {
48-
49-
def apply(readPreference: js.UndefOr[ReadPreference] = js.undefined,
50-
cursor: js.UndefOr[AggregationCursorOptions] = js.undefined,
51-
explain: js.UndefOr[JBoolean] = js.undefined,
52-
allowDiskUse: js.UndefOr[JBoolean] = js.undefined,
53-
maxTimeMS: js.UndefOr[Integer] = js.undefined,
54-
bypassDocumentValidation: js.UndefOr[JBoolean] = js.undefined) = {
55-
val options = new AggregationOptions()
56-
options.readPreference = readPreference
57-
options.cursor = cursor
58-
options.explain = explain
59-
options.allowDiskUse = allowDiskUse
60-
options.maxTimeMS = maxTimeMS
61-
options.bypassDocumentValidation = bypassDocumentValidation
62-
options
63-
}
64-
65-
}
22+
class AggregationOptions(var readPreference: js.UndefOr[ReadPreference] = js.undefined,
23+
var cursor: js.UndefOr[AggregationCursorOptions] = js.undefined,
24+
var explain: js.UndefOr[JBoolean] = js.undefined,
25+
var allowDiskUse: js.UndefOr[JBoolean] = js.undefined,
26+
var maxTimeMS: js.UndefOr[Integer] = js.undefined,
27+
var bypassDocumentValidation: js.UndefOr[JBoolean] = js.undefined) extends js.Object

node/mongodb/src/main/scala/com/github/ldaniels528/meansjs/nodejs/mongodb/Collection.scala

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,23 @@ trait Collection extends js.Object {
119119
* @param callback The command result callback
120120
* @example deleteMany(filter, options, callback)
121121
*/
122-
def deleteMany[T <: js.Any](filter: js.Any, options: DeleteOptions, callback: js.Function2[MongoError, T, Any]): Unit = js.native
122+
def deleteMany(filter: js.Any, options: DeleteOptions, callback: js.Function2[MongoError, DeleteWriteOpResult, Any]): Unit = js.native
123123

124124
/**
125125
* Delete multiple documents on MongoDB
126126
* @param filter The Filter used to select the documents to remove
127127
* @param callback The command result callback
128128
* @example deleteMany(filter, options, callback)
129129
*/
130-
def deleteMany[T <: js.Any](filter: js.Any, callback: js.Function2[MongoError, T, Any]): Unit = js.native
130+
def deleteMany(filter: js.Any, callback: js.Function2[MongoError, DeleteWriteOpResult, Any]): Unit = js.native
131131

132132
/**
133133
* Delete multiple documents on MongoDB
134134
* @param filter The Filter used to select the documents to remove
135135
* @param options Optional settings.
136136
* @example deleteMany(filter, options, callback)
137137
*/
138-
def deleteMany[T <: js.Any](filter: js.Any, options: DeleteOptions = null): js.Promise[T] = js.native
138+
def deleteMany(filter: js.Any, options: DeleteOptions = null): js.Promise[DeleteWriteOpResult] = js.native
139139

140140
/**
141141
* Delete a document on MongoDB
@@ -145,6 +145,20 @@ trait Collection extends js.Object {
145145
*/
146146
def deleteOne(filter: js.Any, options: js.Any, callback: js.Function): Unit = js.native
147147

148+
/**
149+
* Delete a document on MongoDB
150+
* @param filter The Filter used to select the document to remove
151+
* @param callback The command result callback
152+
*/
153+
def deleteOne(filter: js.Any, callback: js.Function): Unit = js.native
154+
155+
/**
156+
* Delete a document on MongoDB
157+
* @param filter The Filter used to select the document to remove
158+
* @param options Optional settings.
159+
*/
160+
def deleteOne(filter: js.Any, options: js.Any = null): js.Promise[DeleteWriteOpResult] = js.native
161+
148162
/**
149163
* The distinct command returns returns a list of distinct values for the given key across a collection.
150164
* @param key Field of the document to find distinct values for.
@@ -667,13 +681,21 @@ trait Collection extends js.Object {
667681
*/
668682
def replaceOne(filter: js.Any, doc: js.Any, options: js.Any, callback: js.Function): Unit = js.native
669683

684+
/**
685+
* Replace a document on MongoDB
686+
* @param filter The Filter used to select the document to update
687+
* @param doc The Document that replaces the matching document
688+
* @param callback The results callback
689+
*/
690+
def replaceOne(filter: js.Any, doc: js.Any, callback: js.Function): Unit = js.native
691+
670692
/**
671693
* Replace a document on MongoDB
672694
* @param filter The Filter used to select the document to update
673695
* @param doc The Document that replaces the matching document
674696
* @param options Optional settings.
675697
*/
676-
def replaceOne[T <: js.Any](filter: js.Any, doc: js.Any, options: js.Any): js.Promise[T] = js.native
698+
def replaceOne[T <: js.Any](filter: js.Any, doc: js.Any, options: js.Any = null): js.Promise[T] = js.native
677699

678700
/**
679701
* Save a document. Simple full document replacement function. Not recommended for efficiency, use atomic operators
@@ -847,8 +869,8 @@ object Collection {
847869
}
848870

849871
@inline
850-
def findOneFuture[T <: js.Any](selector: js.Any, projection: js.Any)(implicit ec: ExecutionContext) = {
851-
callbackMongoFuture[T](coll.find(selector, projection).limit(1).next) map (Option(_))
872+
def findOneFuture[T <: js.Any](selector: js.Any, fields: js.Array[String])(implicit ec: ExecutionContext) = {
873+
callbackMongoFuture[T](coll.find(selector, js.Dictionary(fields.map(_ -> 1): _*)).limit(1).next) map (Option(_))
852874
}
853875

854876
}

node/mongodb/src/main/scala/com/github/ldaniels528/meansjs/nodejs/mongodb/CollectionOptions.scala

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,4 @@ import scala.scalajs.js.annotation.ScalaJSDefined
88
99
*/
1010
@ScalaJSDefined
11-
class CollectionOptions extends js.Object {
12-
var strict: Boolean = _
13-
}
14-
15-
/**
16-
* Mongo Collection Retrieval Options Companion
17-
18-
*/
19-
object CollectionOptions {
20-
21-
def apply(strict: Boolean) = {
22-
val options = new CollectionOptions()
23-
options.strict = strict
24-
options
25-
}
26-
27-
}
11+
class CollectionOptions(var strict: Boolean = false) extends js.Object

node/mongodb/src/main/scala/com/github/ldaniels528/meansjs/nodejs/mongodb/ConnectionOptions.scala

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,8 @@ import scala.scalajs.js.annotation.ScalaJSDefined
99
* @see [[https://mongodb.github.io/node-mongodb-native/api-generated/mongoclient.html#connect]]
1010
*/
1111
@ScalaJSDefined
12-
class ConnectionOptions extends js.Object {
13-
var uri_decode_auth: js.UndefOr[Boolean] = _
14-
var db: js.UndefOr[js.Object] = _
15-
var server: js.UndefOr[js.Object] = _
16-
var replSet: js.UndefOr[js.Object] = _
17-
var mongos: js.UndefOr[js.Object] = _
18-
}
19-
20-
/**
21-
* Mongo Client Connection Options Companion
22-
23-
*/
24-
object ConnectionOptions {
25-
26-
def apply(uri_decode_auth: js.UndefOr[Boolean] = js.undefined,
27-
db: js.UndefOr[js.Object] = js.undefined,
28-
server: js.UndefOr[js.Object] = js.undefined,
29-
replSet: js.UndefOr[js.Object] = js.undefined,
30-
mongos: js.UndefOr[js.Object] = js.undefined) = {
31-
val options = new ConnectionOptions()
32-
options.uri_decode_auth = uri_decode_auth
33-
options.db = db
34-
options.server = server
35-
options.replSet = replSet
36-
options.mongos = mongos
37-
options
38-
}
39-
40-
}
12+
class ConnectionOptions(var uri_decode_auth: js.UndefOr[Boolean] = js.undefined,
13+
var db: js.UndefOr[js.Object] = js.undefined,
14+
var server: js.UndefOr[js.Object] = js.undefined,
15+
var replSet: js.UndefOr[js.Object] = js.undefined,
16+
var mongos: js.UndefOr[js.Object] = js.undefined) extends js.Object

0 commit comments

Comments
 (0)