Here’s the updated README with the correct database name jsondb-yu03
:
jsondb-client
is a server-based JSON database package designed for easy and secure CRUD operations using API requests. The database can be hosted anywhere securely with limits and custom authentication. The UI for the client is under development using Electron.js.
jsondb-client
provides a simple and efficient way to interact with JSON databases similar to traditional MongoDB, but using the jsondb-yu03
server. This package allows you to manage your databases securely and with custom authentication, enabling you to host and manage your data effectively.
Note: The server-side operations are private and protected to prevent theft or unauthorized access. Ensure that your server configurations and credentials are kept secure to prevent any potential misuse.
Install via npm:
npm install jsondb-client
const dbClient = require("jsondb-client");
const db = dbClient.setConnection({
server: 'https://jsondb-yu03.onrender.com',
username: 'testuser.com',
password: '370149ecaf812899',
database: 'jsondb-yu03'
});
const collection = db.Collection('fun');
Creates a new document in the specified collection.
const result = await collection.create({ name: "John Doe", age: 30 });
console.log(result);
Finds all documents matching the query.
const results = await collection.find({ age: { $gt: 20 } });
console.log(results);
Finds a single document matching the query.
const result = await collection.findOne({ name: "John Doe" });
console.log(result);
Finds a document by its unique ID.
const result = await collection.findById("12345");
console.log(result);
Creates or updates a document based on the provided data.
const result = await collection.save({ _id: "12345", name: "Jane Doe" });
console.log(result);
Updates a document by its ID.
const result = await collection.update("12345", { age: 31 });
console.log(result);
Updates a single document matching the query.
const result = await collection.updateOne({ name: "John Doe" }, { age: 31 });
console.log(result);
Updates multiple documents matching the query.
const result = await collection.updateMany({ age: { $lt: 30 } }, { active: false });
console.log(result);
Finds a document by ID and updates it.
const result = await collection.findByIdAndUpdate("12345", { age: 31 });
console.log(result);
Finds a single document matching the query and updates it.
const result = await collection.findOneAndUpdate({ name: "John Doe" }, { age: 31 });
console.log(result);
Deletes a single document matching the query.
const result = await collection.deleteOne({ name: "John Doe" });
console.log(result);
Deletes multiple documents matching the query.
const result = await collection.deleteMany({ age: { $lt: 30 } });
console.log(result);
Finds a document by ID and deletes it.
const result = await collection.findByIdAndDelete("12345");
console.log(result);
Finds a single document matching the query and deletes it.
const result = await collection.findOneAndDelete({ name: "John Doe" });
console.log(result);
Counts the number of documents matching the query.
const count = await collection.countDocuments({ active: true });
console.log(count);
Finds distinct values for a specified field.
const values = await collection.distinct("age", { active: true });
console.log(values);
Performs an aggregation operation.
const results = await collection.aggregate([{ $match: { active: true } }]);
console.log(results);
Populates a field by joining related data.
const result = await collection.populate("user", { active: true });
console.log(result);
Executes a custom command with parameters.
const result = await collection.exec("customCommand", { param1: "value1" });
console.log(result);
To delete a user, make a DELETE
request to the /delete-user
endpoint.
Request:
DELETE /delete-user
Content-Type: application/json
Body:
{
"username": "user_to_delete"
}
Response:
{
"message": "User deleted successfully"
}
Error Response:
{
"message": "User not found"
}
To delete a collection, make a DELETE
request to the /:dbName/:collectionName/delete-collection
endpoint.
Request:
DELETE /:dbName/:collectionName/delete-collection
URL Parameters:
-
dbName
: The name of the database. -
collectionName
: The name of the collection to delete.
Response:
{
"message": "Collection 'collectionName' deleted successfully"
}
Error Response:
{
"message": "Collection not found"
}
To delete a database, make a DELETE
request to the /delete-db/:dbName
endpoint.
Request:
DELETE /delete-db/:dbName
URL Parameters:
-
dbName
: The name of the database to delete.
Response:
{
"message": "Database 'dbName' deleted successfully"
}
Error Response:
{
"message": "Database not found"
}
To create new credentials, use the following curl
command:
curl --location 'https://jsondb-yu03.onrender.com/register' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic bWFub2pnb3dkYWJyODkuY29tOmZmNzkwNTU1Zjk3YTZkNzc=' \
--data '{
"email": "testuser.com"
}'
Response:
{
"message": "User registered successfully",
"username": "testuser.com",
"password": "370149ecaf812899"
}
To create a database, use the following curl
command:
curl --location 'https://jsondb-yu03.onrender.com/add-database' \
--header 'Authorization: Basic dGVzdHVzZXIuY29tOjM3MDE0OWVjYWY4MTI4OTk=' \
--header 'Content-Type: application/json' \
--data '{
"database":"jsondb-yu03"
}'
Response:
{
"message": "Database added successfully",
"databases": [
"jsondb-yu03"
]
}
To create a collection, use the following curl
command:
curl --location --request POST 'https://jsondb-yu03.onrender.com/jsondb-yu03/testcollection' \
--header 'Authorization: Basic dGVzdHVzZXIuY29tOjM3MDE0OWVjYWY4MTI4OTk=' \
--header 'Content-Type: application/json'
Response:
{
"message": "Collection created successfully",
"collection": "testcollection"
}
MIT : manojgowdabr89@gmail.com
Feel free to make any additional adjustments or add more details as needed!