add find logic

This commit is contained in:
Philipp Kunz 2016-09-12 21:36:26 +02:00
parent d1b0a65993
commit 5b093c68e4
4 changed files with 37 additions and 9 deletions

View File

@ -13,7 +13,7 @@ class DbCollection {
*/
find(docMatchArg) {
let done = plugins.q.defer();
this.collection.find().toArray((err, docs) => {
this.collection.find(docMatchArg).toArray((err, docs) => {
if (err) {
throw err;
}
@ -42,7 +42,8 @@ class DbCollection {
checkDocPromiseArray.push(this.checkDoc(docArg));
}
plugins.q.all(checkDocPromiseArray).then(() => {
this.collection.insertMany(docArrayArg);
this.collection.insertMany(docArrayArg)
.then(() => { done.resolve(); });
});
return done.promise;
}
@ -53,4 +54,4 @@ class DbCollection {
}
}
exports.DbCollection = DbCollection;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFDekIsQ0FBQyxDQUQ2QztBQUc5QztJQUVJLFlBQVksT0FBZSxFQUFFLGVBQTZCO1FBQ3RELElBQUksQ0FBQyxVQUFVLEdBQUcsZUFBZSxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLENBQUE7SUFDNUQsQ0FBQztJQUVEOztPQUVHO0lBQ0gsbUJBQW1CLENBQUMsT0FBTyxJQUFJLENBQUM7SUFFaEM7O09BRUc7SUFDSCxJQUFJLENBQUMsV0FBYztRQUNmLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFPLENBQUE7UUFDakMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxJQUFJLEVBQUUsQ0FBQyxPQUFPLENBQUMsQ0FBQ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7WUFDNUIsb0JBQW9CLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQTtRQUNwRCxDQUFDO1FBQ0QsT0FBTyxDQUFDLENBQUMsQ0FBQyxHQUFHLENBQUMsb0JBQW9CLENBQUMsQ0FBQyxJQUFJLENBQUM7WUFDckMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxVQUFVLENBQUMsV0FBVyxDQUFDO2lCQUNsQyxJQUFJLENBQUMsUUFBUSxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUEsQ0FBQyxDQUFDLENBQUMsQ0FBQTtRQUN2QyxDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7SUFFTyxRQUFRLENBQUMsR0FBTTtRQUNuQixJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBUSxDQUFBO1FBQ2xDLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNkLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7QUFDTCxDQUFDO0FBeERZLG9CQUFZLGVBd0R4QixDQUFBIn0=

View File

@ -32,16 +32,29 @@ describe('smartdata', function () {
it('should create a collection', function () {
testDbCollection = new smartdata.DbCollection('something', testDbConnection);
});
it('should insert something into the collection', function (done) {
it('should insert a doc into the collection', function (done) {
testDbCollection.insertOne({ hello: 'test' }).then(() => { done(); });
});
it('should find all instances of test', function (done) {
it('should find all docs of testDbCollection', function (done) {
testDbCollection.find({}).then((resultArray) => {
console.log(resultArray);
should(resultArray[0].hello).equal('test');
done();
});
});
it('should insert many docs into the collection', function (done) {
testDbCollection.insertMany([
{ hello: 'test' },
{ wow: 'what is this', wow2: 3 }
]).then(() => { done(); });
});
it('should find a specified doc', function (done) {
testDbCollection.find({ 'wow2': { '$exists': true } }).then((resultArray) => {
console.log(resultArray);
should(resultArray[0].wow2).equal(3);
done();
}).catch(console.log);
});
it('should close the db Connection', function () {
testDbConnection.close();
});
@ -58,4 +71,4 @@ describe('mongodb', function () {
mongoChildProcess.kill('SIGTERM');
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FFUCxDQUFDLENBRm9CO0FBRXJCLE1BQVksT0FBTyxXQUFNLFNBQ3pCLENBQUMsQ0FEaUM7QUFDbEMsTUFBWSxNQUFNLFdBQU0sUUFDeEIsQ0FBQyxDQUQrQjtBQUNoQyxNQUFZLFdBQVcsV0FBTSxhQUc3QixDQUFDLENBSHlDO0FBRTFDLG9CQUFvQjtBQUNwQixNQUFZLFNBQVMsV0FBTSxlQUUzQixDQUFDLENBRnlDO0FBRTFDLElBQUksaUJBQWlCLENBQUE7QUFDckIsSUFBSSxnQkFBd0MsQ0FBQTtBQUM1QyxJQUFJLGdCQUE2QyxDQUFBO0FBRWpELFFBQVEsQ0FBQyxTQUFTLEVBQUU7SUFDaEIsRUFBRSxDQUFDLHNCQUFzQixFQUFFLFVBQVUsSUFBSTtRQUNyQyxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1FBQ25CLGlCQUFpQixHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsMENBQTBDLEVBQUUsRUFBRSxLQUFLLEVBQUUsSUFBSSxFQUFFLE1BQU0sRUFBRSxJQUFJLEVBQUUsQ0FBQyxDQUFBO1FBQzNHLElBQUksVUFBVSxHQUFHLEtBQUssQ0FBQTtRQUN0QixpQkFBaUIsQ0FBQyxNQUFNLENBQUMsRUFBRSxDQUFDLE1BQU0sRUFBRSxVQUFVLElBQUk7WUFDOUMsT0FBTyxDQUFDLEd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FBQyxJQUFJLENBQUMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUE7WUFDcEMsSUFBSSxFQUFFLENBQUE7UUFDVixDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFBO0lBQ3pCLENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLGdDQUFnQyxFQUFFO1FBQ2pDLGdCQUFnQixDQUFDLEtBQUssRUFBRSxDQUFBO0lBQzVCLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUE7QUFFRixRQUFRLENBQUMsU0FBUyxFQUFFO0lBQ2hCLEVBQUUsQ0FBQyxxQkFBcUIsRUFBRSxVQUFVLElBQUk7UUFDcEMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxLQUFLLENBQUMsQ0FBQTtRQUNuQixpQkFBaUIsQ0FBQyxNQUFNLENBQUMsRUFBRSxDQUFDLE1BQU0sRUFBRSxVQUFVLElBQUk7WUFDOUMsRUFBRSxDQUFDLENBQUMsZ0JBQWdCLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQztnQkFDOUIsSUFBSSxFQUFFLENBQUE7WUFDVixDQUFDO1FBQ0wsQ0FBQyxDQUFDLENBQUE7UUFDRixPQUFPLENBQUMsSUFBSSxDQUFDLHdDQUF3QyxDQUFDLENBQUE7UUFDdEQsaUJBQWlCLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxDQUFBO0lBQ3JDLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==

View File

@ -35,16 +35,29 @@ describe('smartdata', function () {
it('should create a collection', function () {
testDbCollection = new smartdata.DbCollection('something', testDbConnection)
})
it('should insert something into the collection', function (done) {
it('should insert a doc into the collection', function (done) {
testDbCollection.insertOne({ hello: 'test' }).then(() => { done() })
})
it('should find all instances of test', function (done) {
it('should find all docs of testDbCollection', function (done) {
testDbCollection.find({}).then((resultArray) => {
console.log(resultArray)
should(resultArray[0].hello).equal('test')
done()
})
})
it('should insert many docs into the collection', function (done) {
testDbCollection.insertMany([
{ hello: 'test' },
{ wow: 'what is this', wow2: 3}
]).then(() => { done() })
})
it('should find a specified doc', function (done) {
testDbCollection.find({'wow2': {'$exists': true}}).then((resultArray) => {
console.log(resultArray)
should(resultArray[0].wow2).equal(3)
done()
}).catch(console.log)
})
it('should close the db Connection', function () {
testDbConnection.close()
})

View File

@ -17,7 +17,7 @@ export class DbCollection<T> {
*/
find(docMatchArg: T): plugins.q.Promise<T[]> {
let done = plugins.q.defer<T[]>()
this.collection.find().toArray((err, docs) => {
this.collection.find(docMatchArg).toArray((err, docs) => {
if (err) { throw err }
done.resolve(docs)
})
@ -47,6 +47,7 @@ export class DbCollection<T> {
}
plugins.q.all(checkDocPromiseArray).then(() => {
this.collection.insertMany(docArrayArg)
.then(() => { done.resolve() })
})
return done.promise
}