Giter VIP home page Giter VIP logo

lealone-mongo's Introduction

Lealone 是一个高度兼容 MongoDB 的文档数据库,可以使用 MongoDB 的各种客户端访问 Lealone。

编译运行需要

  • JDK 1.8+

  • Maven 3.8+

  • MongoDB 版本支持 4.x 到 7.x 系列

打包插件

运行 mvn clean package -Dmaven.test.skip=true

生成 jar 包 target\lealone-mongo-plugin-6.0.0-SNAPSHOT.jar

假设 jar 包的绝对路径是 E:\lealone\lealone-plugins\mongo\target\lealone-mongo-plugin-6.0.0-SNAPSHOT.jar

下载 Lealone

lealone-6.0.0-SNAPSHOT.jar

Lealone 只有一个 jar 包,下载下来之后随意放到一个目录即可

也可以从源代码构建最新版本,请阅读文档: 从源码构建 Lealone

启动 Lealone 数据库

打开一个新的命令行窗口,运行: java -jar lealone-6.0.0-SNAPSHOT.jar

Lealone version: 6.0.0-SNAPSHOT
Use default config
Base dir: E:/lealone/lealone-6/target/lealone_data
Init storage engines: 4 ms
Init transaction engines: 32 ms
Init sql engines: 4 ms
Init protocol server engines: 9 ms
Init lealone database: 104 ms
TcpServer started, host: 127.0.0.1, port: 9210
Total time: 261 ms (Load config: 2 ms, Init: 258 ms, Start: 1 ms)
Exit with Ctrl+C

要停止 Lealone,直接按 Ctrl + C

运行插件

打开一个新的命令行窗口,运行: java -jar lealone-6.0.0-SNAPSHOT.jar -client

然后执行以下命令创建并启动插件:

create plugin mongo
  implement by 'com.lealone.plugins.mongo.MongoPlugin' 
  class path 'E:\lealone\lealone-plugins\mongo\target\lealone-mongo-plugin-6.0.0-SNAPSHOT.jar'
  --端口号默认就是27017,如果被其他进程占用了可以改成别的
  parameters (port=27017);
 
start plugin mongo;

要 stop 和 drop 插件可以执行以下命令:

stop plugin mongo;

drop plugin mongo;

执行 stop plugin 只是把插件对应的服务停掉,可以再次通过执行 start plugin 启动插件

执行 drop plugin 会把插件占用的内存资源都释放掉,需要再次执行 create plugin 才能重新启动插件

使用 MongoDB Shell 客户端执行命令访问 Lealone

需要下载 MongoDB Shell 客户端

打开一个新的命令行窗口,运行: mongosh mongodb://127.0.0.1:27017/test

Connecting to:          mongodb://127.0.0.1:27017/test?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.9.1
Using MongoDB:          6.0.0
Using Mongosh:          1.9.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

test> db.runCommand({ insert: "c1", documents: [{ _id: 1, user: "u1", age: 12, status: "A"}] });
{ ok: 1, n: 1 }
test>

test> db.runCommand({ find: "c1", filter: {_id: 1} });
{
  cursor: {
    id: Long("0"),
    ns: 'test.c1',
    firstBatch: [ { _id: Long("1"), user: 'u1', age: 12, status: 'A' } ]
  },
  ok: 1
}
test>

test> db.runCommand({ update: "c1", updates: [ { q: { _id: 1 }, u: { $set: { user: "u11" } } }] });
{ ok: 1, n: 1, nModified: 1 }
test>

test> db.runCommand({"aggregate": "c1", "pipeline": [{"$match": {}}, {"$group": {"_id": 1, "n": {"$sum": 1}}}], "cursor": {}});
{
  cursor: { id: Long("0"), ns: 'test.c1', firstBatch: [ { _id: 1, n: 1 } ] },
  ok: 1
}
test>

test> db.runCommand({ delete: "c1", deletes: [ { q: { _id: 1 }, limit: 1 } ] });
{ ok: 1, n: 1 }
test>

test> db.runCommand({ find: "c1", filter: {_id: 1} });
{ cursor: { id: Long("0"), ns: 'test.c1', firstBatch: [] }, ok: 1 }
test>

MongoDB 文档

MongoDB 各种命令的用法请参考 官方文档

lealone-mongo's People

Contributors

codefollower avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.