1.0.6 • Published 7 months ago
@storecraft/database-mongodb v1.0.6
Storecraft MongoDB driver for node / deno / bun
Official mongodb
driver for StoreCraft
on Node.js / Deno / Bun platforms.
Also, official support for mongo-db as vector store.
npm i @storecraft/database-mongodb
usage
import 'dotenv/config';
import http from "node:http";
import { App } from '@storecraft/core'
import { NodePlatform } from '@storecraft/core/platform/node';
import { MongoDB } from '@storecraft/database-mongodb'
import { migrateToLatest } from '@storecraft/database-mongodb/migrate.js'
import { NodeLocalStorage } from '@storecraft/core/storage/node'
import { MongoVectorStore } from '@storecraft/database-mongodb/vector-store'
const app = new App()
.withPlatform(new NodePlatform())
.withDatabase(
new MongoDB(
{
url: process.env.MONGODB_URL,
db_name: process.env.MONGODB_NAME,
}
)
)
.withVectorStore(
new MongoVectorStore(
{
embedder: new OpenAIEmbedder(),
url: process.env.MONGODB_VECTOR_STORE_URL ?? process.env.MONGODB_URL,
db_name: process.env.MONGODB_VECTOR_STORE_DB_NAME ?? process.env.MONGODB_NAME,
}
)
)
.init();
await migrateToLatest(app.__show_me_everything.db, false);
await app.__show_me_everything.vector_store.createVectorIndex();
http.createServer(app.handler).listen(
8000,
() => {
app.print_banner('http://localhost:8000');
}
);
Storecraft will search the following env
variables
MONGODB_NAME=main
MONGODB_URL='mongodb-connection-string'
// also, this will default into `MONGODB_NAME`
MONGODB_VECTOR_STORE_DB_NAME=vector-store
// also, this will default into `MONGODB_URL`
MONGODB_VECTOR_STORE_URL='mongodb-connection-string'
So, you can instantiate with empty config
.withDatabase(
new MongoDB()
)
.withVectorStore(
new MongoVectorStore(
{
embedder: new OpenAIEmbedder(),
}
)
)
Testing Locally (I recommend to use Atlas
)
- Start a
mongo-db
server withdocker
First, make sure you have docker
installed,
Then, run
npm run database-mongodb:docker-compose-up
- create Environment
create .env
file with
MONGODB_URL="mongodb://127.0.0.1:27017/?replicaSet=rs0"
MONGODB_NAME="main"
- Run
tests/runner.test.js
npm run database-mongodb:test
Author: Tomer Shalev <tomer.shalev@gmail.com>
1.0.19
2 months ago
1.0.18
3 months ago
1.0.17
3 months ago
1.0.16
3 months ago
1.2.6
1 month ago
1.2.5
1 month ago
1.3.0
27 days ago
1.0.21
2 months ago
1.0.20
2 months ago
1.0.15
3 months ago
1.0.14
3 months ago
1.0.9
5 months ago
1.0.8
5 months ago
1.0.7
6 months ago
1.0.6
7 months ago
1.0.11
5 months ago
1.0.10
5 months ago
1.0.13
4 months ago
1.0.12
5 months ago
1.0.5
8 months ago
1.0.4
8 months ago
1.0.3
8 months ago
1.0.2
9 months ago
1.0.1
10 months ago