https://github.com/scalajs-io/mongodb
The official MongoDB driver for Node.js
https://github.com/scalajs-io/mongodb
mean-stack mongo mongodb mongodb-binding node nodejs npm scala scalajs
Last synced: 2 months ago
JSON representation
The official MongoDB driver for Node.js
- Host: GitHub
- URL: https://github.com/scalajs-io/mongodb
- Owner: scalajs-io
- License: apache-2.0
- Created: 2017-02-05T00:16:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-06-17T23:10:06.000Z (almost 7 years ago)
- Last Synced: 2025-01-17T22:42:29.415Z (over 1 year ago)
- Topics: mean-stack, mongo, mongodb, mongodb-binding, node, nodejs, npm, scala, scalajs
- Language: Scala
- Homepage:
- Size: 134 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
MongoDB API for Scala.js
================================
[mongodb](http://mongodb.github.io/node-mongodb-native/2.2/api/) - The official MongoDB driver for Node.js.
### Description
The official MongoDB driver for Node.js. Provides a high-level API on top of mongodb-core that is meant for end users.
* [ScalaJs.io v0.3.x](https://github.com/scalajs-io/scalajs-io)
* [SBT v1.2.x](http://www.scala-sbt.org/download.html)
### Build/publish the SDK locally
```bash
$ sbt clean publish-local
```
### Running the tests
Before running the tests the first time, you must ensure the npm packages are installed:
```bash
$ npm install
```
Then you can run the tests:
```bash
$ sbt test
```
### Examples
```scala
import io.scalajs.JSON
import io.scalajs.nodejs._
import io.scalajs.npm.mongodb._
import scalajs.js
val url = "mongodb://localhost:27017/test"
MongoClient.connect(url, (err, db) => {
val col = db.collection("streams")
// Insert some documents
col.insertMany(js.Array(new Sample(a = 1), new Sample(a = 2), new Sample(a = 3)), (err, iwr) => {
// Get the results using a find stream
val stream = col.find[Sample](doc()).stream()
stream.onData[Sample](doc => console.log(doc))
stream.onEnd(() => db.close())
})
})
class Sample(var _id: js.UndefOr[ObjectID] = js.undefined,
var a: js.UndefOr[Int] = js.undefined)
extends js.Object
```
### Artifacts and Resolvers
To add the `MongoDB` binding to your project, add the following to your build.sbt:
```sbt
libraryDependencies += "io.scalajs.npm" %%% "mongodb" % "0.5.0"
```
Optionally, you may add the Sonatype Repository resolver:
```sbt
resolvers += Resolver.sonatypeRepo("releases")
```