https://github.com/guxingke/sql2mongo
sql query to mongo query
https://github.com/guxingke/sql2mongo
antlr4 cli mongo-query sql-query
Last synced: 10 months ago
JSON representation
sql query to mongo query
- Host: GitHub
- URL: https://github.com/guxingke/sql2mongo
- Owner: guxingke
- Created: 2018-11-30T07:53:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-13T11:05:14.000Z (almost 6 years ago)
- Last Synced: 2025-03-16T07:26:28.532Z (over 1 year ago)
- Topics: antlr4, cli, mongo-query, sql-query
- Language: Java
- Homepage: https://github.com/guxingke/sql2mongo
- Size: 8.51 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sql2Mongo
sql query convert to mongo query
e.g:
```
select _id,nickname from user where _id in (100002,100003) order by _id desc limit 1,1
```
=>
```
db.user.find({_id: {$in:[100002,100003]}},{_id:1, nickname:1}).sort({_id:-1}).skip(1).limit(1)
```
# PRE
- maven 3.3+
- jdk 1.8+
- graalvm 1.0+
# Build
```bash
mvn clean package
./build.sh # build binary executable file named s2m.
```
# Install
```bash
brew tap guxingke/homebrew-repo && brew install s2m
```
# Showcase
## My Case
```bash
# base
$ s2m "select * from user where id >= 1 and id = 100002"
#->
db.user.find({$and: [{id: {$gte: 1}},{id: {$eq: 100002}}]},{}).sort({_id:-1}).skip(0).limit(100)
```
```bash
# shortcut.
$ which mp
# =>
mp () {
mq=`s2m "$*"`
#echo "__mq: $mq"
mongo [ip]:[port]/[db] --quiet --eval "$mq.forEach(printjson)"
}
# base query
$ mp "select _id,nickname from user where _id in (100002,100003) order by _id desc limit 10"
# =>
{ "_id" : NumberLong(100003), "nickname" : "就是辣么帅2323" }
{ "_id" : NumberLong(100002), "nickname" : "下江" }
# special limit
$ mp "select _id,nickname from user where _id in (100002,100003) order by _id desc limit 1,1"
# =>
{ "_id" : NumberLong(100002), "nickname" : "下江" }
# collaboration with other unix tool
$ mp "select _id,nickname from user where _id in (100002,100003) order by _id desc limit 10" | b2j | jq .nickname
# =>
"就是辣么帅2323"
"下江"
```

---
# Feature
- support base binary op.
=,!=,> ...
in, not in.
- and, or, ().
- build the binary executable file
# Note
it build for myself.
# Changelog
- basic available