This page covers the path from installing monSQLize to validating a minimal MongoDB-backed collection:
- Installation
- Initializing
MonSQLize connect()collection()- Basic writes and queries
- Closing the connection
- Where to continue with basic usage
npm install monsqlize- Node.js 18 or newer.
- A MongoDB URI, such as
mongodb://localhost:27017. - Optional Redis, SSH tunnel, cache, Model, and sync features are configured only when your application uses them.
import MonSQLize from 'monsqlize';
const msq = new MonSQLize({
type: 'mongodb',
databaseName: 'mydb',
config: { uri: 'mongodb://localhost:27017' },
});
await msq.connect();
const users = msq.collection('users');
await users.insertOne({
username: 'ada',
email: 'ada@example.com',
createdAt: new Date(),
});
const user = await users.findOne({ email: 'ada@example.com' });
console.log(user);
await msq.close();If you are validating the minimal path inside this repository, run:
npm run build
npm run test:examplesThe current official example is examples/quick-start/basic-connect.ts. During verification, it is compiled before it runs. The example:
- Starts an in-memory MongoDB instance.
- Creates and connects a
MonSQLizeinstance. - Inserts one user document.
- Reads the document back and prints the result.
- Closes the connection and cleans up the temporary database.
- Continue with common CRUD, pagination, cache, and Model entry points in
basic-operations.md. - Review all constructor options in
configuration.md. - Learn query details in
find.md,findOne.md, andfindPage.md. - Compare runnable examples in
examples.md. - Open the source examples on GitHub:
- Calling
collection()beforeconnect()triggersNOT_CONNECTED. - Missing
config.uritriggersINVALID_CONFIG. - Application code should import from the package root:
import MonSQLize from 'monsqlize'orconst MonSQLize = require('monsqlize').