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 🙏

© 2024 – Pkg Stats / Ryan Hefner

awaitmongodb

v1.0.4

Published

Little lib for await mongodb result

Downloads

12

Readme

"# Await-MongoDB" little await mongodb helper All methods are described here Standard view:

const mongo = require('awaitmongodb')
var result = await awaitmongo(url, dbname, action, collection, query, newvalue)
  • url - url of mongodb, looks like this - 'mongodb://:@gs111111.mlab.com:11111/kdjdh23857'
  • dbname - name of database
  • action - action to do(insertOne, etc)
  • collection - collection name
  • query - object to insert|find etc
  • newvalue - object, updates query

This function allows you to perform various operations in a MongoDB database, such as finding, sorting, inserting, deleting, and updating data.

Parameters

  • url (string): The URL for connecting to the database.
  • dbname (string): The name of the database.
  • action (string): The action to perform. Possible values:
    • 'find': Retrieves documents that match the query criteria.
    • 'sort': Sorts the result set according to the specified sort criteria.
    • 'insertOne': Inserts a single document.
    • 'insertMany': Inserts multiple documents.
    • 'deleteOne': Deletes a single document.
    • 'deleteMany': Deletes multiple documents.
    • 'updateOne': Updates a single document.
    • 'updateMany': Updates multiple documents.
    • 'createIndex': Creates an index on the specified field(s).
  • collection (string): The name of the collection to perform the action on.
  • query (object, optional): The query to perform.
  • newvalue (object, optional): The new value for the operation.

Returns

A Promise that resolves with the result of the operation in the database. The result will depend on the action performed:

  • 'find' or 'sort': An array of documents that match the query.
  • 'insertOne' or 'insertMany': An object with information about the insert operation.
  • 'deleteOne' or 'deleteMany': An object with information about the delete operation.
  • 'updateOne' or 'updateMany': An object with information about the update operation.
  • 'createIndex': An object with information about the index creation.

Examples

Find or Sort

const result = await mongo(url, 'mydb', 'find', 'mycollection', { name: 'John' });
console.log(result); // Array of documents that match the query

const sortedResult = await mongo(url, 'mydb', 'sort', 'mycollection', { name: 'John' }, { age: 1 });
console.log(sortedResult); // Array of documents sorted by age

Insert One

const result = await mongo(url, 'mydb', 'insertOne', 'mycollection', { name: 'John' });
console.log(result); // Object with information about the insert operation

Insert Many

const result = await mongo(url, 'mydb', 'insertMany', 'mycollection', [{ name: 'John' }, { name: 'Doe' }]);
console.log(result); // Object with information about the insert operation

Delete One

const result = await mongo(url, 'mydb', 'deleteOne', 'mycollection', { name: 'John' });
console.log(result); // Object with information about the delete operation

Delete Many

const result = await mongo(url, 'mydb', 'deleteMany', 'mycollection', { name: 'John' });
console.log(result); // Object with information about the delete operation

Update One

const result = await mongo(url, 'mydb', 'updateOne', 'mycollection', { name: 'John' }, { $set: { age: 30 } });
console.log(result); // Object with information about the update operation

Update Many

const result = await mongo(url, 'mydb', 'updateMany', 'mycollection', { name: 'John' }, { $set: { age: 30 } });
console.log(result); // Object with information about the update operation

Create Index

const result = await mongo(url, 'mydb', 'createIndex', 'mycollection', { name: 1 });
console.log(result); // Object with information about the index creation