@mongosh/java-shell
Java application that uses mongosh-shell-api node module and MongoDB java driver to run mongo shell on JVM
Last updated 9 months ago by mcasimir .
SSPL · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @mongosh/java-shell 
SYNC missed versions from official npm registry.

MongoDB Shell for JVM

MongoDB Shell for JVM runs shell commands e.g. db.students.find({name: "Peter"}) and returns results in a type safe manner.

Usage

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClients;
import com.mongodb.mongosh.MongoShell;
import com.mongodb.mongosh.result.Cursor;
import com.mongodb.mongosh.result.CursorResult;
import org.bson.Document;

/* ... */

MongoClientSettings settings = MongoClientSettings.builder()
    .applyConnectionString(new ConnectionString("mongodb://localhost:27017"))
    .build();

try (MongoShell shell = new MongoShell(MongoClients.create(settings))) {
  shell.eval("use admin");
  CursorResult result = (CursorResult) shell.eval("db.companies.find()").get();
  Cursor cursor = result.getValue();
  while (cursor.hasNext()) {
    Document doc = cursor.next();
    System.out.println(doc);
  }
}
catch (InterruptedException | ExecutionException e) {
  e.printStackTrace();
}

Running Tests

Start MongoDB instance and set URI variable in util.kt to MongoDB URI string e.g. mongodb://localhost:27017

./gradlew test

Current Tags

  • 0.0.1-alpha.13                                ...           latest (9 months ago)

8 Versions

  • 0.0.1-alpha.13                                ...           9 months ago
  • 0.0.1-alpha.12                                ...           9 months ago
  • 0.0.1-alpha.11                                ...           9 months ago
  • 0.0.1-alpha.10                                ...           10 months ago
  • 0.0.1-alpha.9                                ...           10 months ago
  • 0.0.1-alpha.6                                ...           10 months ago
  • 0.0.1-alpha.4                                ...           10 months ago
  • 0.0.1-alpha.3                                ...           10 months ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 8
Dependencies (0)
None
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |