Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

senter-mongo-repository

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

senter-mongo-repository - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

22

mongoReposotory.js

@@ -63,2 +63,24 @@ const MongoClient = require('mongodb').MongoClient;

async search(searchTerm, limit = 1000) {
if (!searchTerm) {
throw Error("Mongo repository: search error: searchTerm cannot be null or empty");
}
try {
await this.init();
let docs = await this._collection.find(searchTerm).limit(limit).toArray();
docs.forEach(x => {
x.id = x._id;
delete x._id;
});
return docs;
} catch (err) {
console.log(err.stack);
throw err;
}
}
async create(userId, document) {

@@ -65,0 +87,0 @@ if (!document) {

2

package.json
{
"name": "senter-mongo-repository",
"version": "1.0.5",
"version": "1.0.6",
"description": "Contain methods to work with mongo db",

@@ -5,0 +5,0 @@ "main": "mongoReposotory.js",

@@ -5,3 +5,3 @@ const MongoRepository = require("../mongoReposotory");

const connectionString = '';
const connectionString = 'mongodb+srv://sandbox:MLiGyVdt97ECQSbO876hPtGExk36sp15@sandbox-5zqkh.mongodb.net/test?retryWrites=true&w=majority';
const dbName = 'senter';

@@ -332,2 +332,58 @@ const collectionName = MongoRepository.ContactListsCollectionName;

});
});
describe("search", () => {
var repository;
var userId;
var client;
var ids = [];
beforeEach(async () => {
userId = lastUserId.toString();
lastUserId++;
repository = new MongoRepository(connectionString, dbName, collectionName);
client = new MongoClient(connectionString, options);
await client.connect();
await repository.init();
});
afterEach(async () => {
const col = client.db(dbName).collection(collectionName);
for (let index = 0; index < ids.length; index++) {
const id = ids[index];
await col.deleteOne({ _id: id });
}
await client.close();
await repository.close();
});
test("should retrieve exisiting object by id and userId", async () => {
ids.push(uuidv4());
ids.push(uuidv4());
ids.push(uuidv4());
const col = client.db(dbName).collection(collectionName);
await col.insertOne({
_id: ids[0],
userId: userId,
name: "should retrieve exisiting object by id and userId"
});
await col.insertOne({
_id: ids[1],
userId: userId,
name: "should retrieve exisiting object by id and userId"
});
await col.insertOne({
_id: ids[2],
userId: userId,
name: "should retrieve exisiting object by id and userId"
});
const result = await repository.search({
userId: userId
});
expect(result).toBeDefined();
expect(result.length).toBe(3);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc