npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

lia-mongo

v1.2.1

Published

A simplified MongoDB key-value store for casual developers.

Downloads

68

Readme

LiaMongo

Introduction

LiaMongo is a simplified MongoDB key-value store designed to make MongoDB operations easier for casual developers. It provides a straightforward interface for storing and retrieving key-value pairs in MongoDB collections.

Rationale

Many developers find MongoDB's document-oriented approach flexible but sometimes overwhelming, especially for simple key-value storage scenarios. LiaMongo aims to simplify this process by abstracting away much of the complexity of interacting with MongoDB.

Target Users

LiaMongo is targeted towards developers who need a simple and intuitive way to store key-value data in MongoDB without dealing with the intricacies of the MongoDB driver or schema design.

Advantage of Easiness

The primary advantage of LiaMongo is its ease of use. By providing a straightforward API for common MongoDB operations, developers can quickly integrate LiaMongo into their projects without needing extensive knowledge of MongoDB internals.

Disadvantage of Key-Value Schema

While the key-value schema provides simplicity and flexibility, it may not be suitable for all use cases, especially those requiring complex querying or relationships between data. Additionally, the lack of schema validation for the value field may lead to inconsistencies in data storage.

Installation

npm install lia-mongo

How to Import

const LiaMongo = require('lia-mongo');

Methods

Constructor

Description

Creates a new instance of LiaMongo.

Arguments

  • options: An object containing configuration options.
    • uri: MongoDB connection URI.
    • collection: Name of the MongoDB collection to use.
    • isOwnHost: (Optional) Boolean indicating whether the MongoDB instance is hosted on the same machine. Default is false.
    • ignoreError: (Optional) Boolean indicating whether to ignore connection errors. Default is false.
    • allowClear: (Optional) Boolean indicating whether clearing the collection is allowed. Default is false.
    • createConnection: (Optional) Boolean indicating whether to create a new connection. Default is false.

Returns

A new instance of LiaMongo.

Usage

const liaMongo = new LiaMongo({
  uri: "mongodb://localhost:27017/mydb",
  collection: "myCollection",
  isOwnHost: true,
});

start(ignoreReconnect)

Description

Connects to the MongoDB database.

Arguments

  • ignoreReconnect: (Optional) Boolean to ignore reconnection errors if already connected.

Returns

Promise.

Usage

await liaMongo.start();

get(key)

Description

Retrieves the value associated with the given key.

Arguments

  • key: The key to retrieve the value for.

Returns

Promise | null: The value associated with the key, or null if not found.

Usage

const value = await liaMongo.get("myKey");

put(key, value)

Description

Stores a key-value pair in the MongoDB collection.

Arguments

  • key: The key to store.
  • value: The value to store.

Returns

Promise.

Usage

await liaMongo.put("myKey", "myValue");

remove(key)

Description

Removes the key-value pair with the given key from the MongoDB collection.

Arguments

  • key: The key to remove.

Returns

Promise.

Usage

await liaMongo.remove("myKey");

containsKey(key)

Description

Checks if the given key exists in the MongoDB collection.

Arguments

  • key: The key to check.

Returns

Promise: True if the key exists, false otherwise.

Usage

const exists = await liaMongo.containsKey("myKey");

size()

Description

Gets the number of key-value pairs in the MongoDB collection.

Returns

Promise: The number of key-value pairs.

Usage

const size = await liaMongo.size();

clear()

Description

Clears all key-value pairs from the MongoDB collection.

Returns

Promise.

Usage

await liaMongo.clear();

keys()

Description

Retrieves an array of all keys in the MongoDB collection.

Returns

Promise<string[]>: An array of keys.

Usage

const keys = await liaMongo.keys();

values()

Description

Retrieves an array of all values in the MongoDB collection.

Returns

Promise<any[]>: An array of values.

Usage

const values = await liaMongo.values();

entries()

Description

Retrieves an array of all key-value pairs in the MongoDB collection.

Returns

Promise<{ key: string, value: any }[]>: An array of key-value pairs.

Usage

const entries = await liaMongo.entries();

load()

Description

Loads all key-value pairs from the MongoDB collection into an object.

Returns

Promise: An object containing all key-value pairs.

Usage

const data = await liaMongo.load();

preProc(data)

Description

Pre-processes the given data.

Arguments

  • data: The data to pre-process.

Returns

Promise: The pre-processed data.

Usage

const preProcessedData = await liaMongo.preProc(data);

toObject()

Description

Converts all key-value pairs in the MongoDB collection into an object.

Returns

Promise: An object containing all key-value pairs.

Usage

const objectData = await liaMongo.toObject();

toJSON()

Description

Converts all key-value pairs in the MongoDB collection into a JSON object.

Returns

Promise: A JSON object containing all key-value pairs.

Usage

const jsonData = await liaMongo.toJSON();

Symbol.iterator

Description

Returns an iterator for the key-value pairs in the MongoDB collection.

Returns

AsyncIterator<{ key: string, value: any }>.

Usage

for await (const entry of liaMongo) {
  console.log(entry);
}

iKeys()

Description

Returns an iterator for the keys in the MongoDB collection.

Returns

AsyncIterator.

Usage

for await (const key of liaMongo.iKeys()) {
  console.log(key);
}

iValues()

Description

Returns an iterator for the values in the MongoDB collection.

Returns

AsyncIterator.

Usage

for await (const value of liaMongo.iValues()) {
  console.log(value);
}

bulkPut(pairs)

Description

Inserts or updates multiple key-value pairs in the MongoDB collection in a single operation.

Arguments

  • pairs: An object where keys are the keys to insert/update and values are the corresponding values.

Returns

Promise.

Usage

await liaMongo.bulkPut({
  key1: "value1",
  key2: "value2",
});

bulkGet(...keys)

Description

Retrieves values for multiple keys in a single operation. This method accepts individual keys or an array of keys.

Arguments

  • ...keys: One or more keys or an array of keys to retrieve values for.

Returns

Promise<any[]>: An array of values corresponding to the given keys. Returns an empty array if no values are found or if an error occurs and ignoreError is set to true.

Usage

const values = await liaMongo.bulkGet("key1", "key2");

Or

const values = await liaMongo.bulkGet(["key1", "key2"]);

Static Schema

Description

The schema used for storing key-value pairs in MongoDB.

Usage

LiaMongo.schema;

Credits

LiaMongo npm package created by Liane Cagara.