New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

loopback-connector-mongodb

Package Overview
Dependencies
Maintainers
4
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loopback-connector-mongodb - npm Package Compare versions

Comparing version 1.6.0 to 1.7.0

test/persistence-hooks.test.js

92

CHANGES.md

@@ -0,1 +1,19 @@

2015-02-08, Version 1.7.0
=========================
* Check if result is null (Raymond Feng)
* Disable extended tests if mongodb version is lower than 2.6 (Raymond Feng)
* Include tests of persistence hooks from juggler. (Miroslav Bajtoš)
* Update `should` to the latest version `4.6.3` (Miroslav Bajtoš)
* Fix unit-tests on iojs 1.0 (Miroslav Bajtoš)
* Tidy up the null check (Raymond Feng)
* Added options to like/nlike operator to allow for regex flags (Andrew Burgess)
2015-01-23, Version 1.6.0

@@ -252,76 +270,2 @@ =========================

* Bump version (Raymond Feng)
* Use peer dep for loopback-datasource-juggler (Raymond Feng)
* Remove blanket (Raymond Feng)
* Update docs.json (Rand McKinney)
* Bump the version and remove the blanket dep (Raymond Feng)
* Bump version (Ritchie Martori)
* Add peer dep and bump version (Ritchie Martori)
* Pass name/settings to super class (Raymond Feng)
* Inherit from Connector (Raymond Feng)
* Finalize package.json for sls-1.0.0 (Raymond Feng)
* Update mongodb driver dependency (Raymond Feng)
* Add error information if connection fails (Raymond Feng)
* Add debug info for connection (Raymond Feng)
* Add error reporting (Raymond Feng)
* Connect to MongoDB before a CRUD operation is requested (Raymond Feng)
* Add keywords to package.json (Raymond Feng)
2013-09-12, Version strongloopsuite-1.0.0-5
===========================================
2013-09-12, Version strongloopsuite-1.0.0-4
===========================================
* Update mongodb driver dependency (Raymond Feng)
* Add error information if connection fails (Raymond Feng)
* Add debug info for connection (Raymond Feng)
* Add error reporting (Raymond Feng)
* Connect to MongoDB before a CRUD operation is requested (Raymond Feng)
2013-09-11, Version strongloopsuite-1.0.0-3
===========================================
* Add keywords to package.json (Raymond Feng)
2013-09-10, Version strongloopsuite-1.0.0-2
===========================================
* Finalize package.json for sls-1.0.0 (Raymond Feng)
* Changed tag to strongloopsuite-1.0.0-2 (cgole)
2013-09-05, Version strongloopsuite-1.0.0-1
===========================================
2013-09-05, Version strongloopsuite-1.0.0-0
===========================================
* First release!

@@ -249,3 +249,3 @@ /*!

}
callback && callback(err, result.ops);
callback && callback(err, result && result.ops);
});

@@ -383,3 +383,3 @@ };

}
var object = result.value;
var object = result && result.value;
if (!err && !object) {

@@ -389,4 +389,6 @@ // No result

}
self.setIdValue(model, object, id);
object && idName !== '_id' && delete object._id;
if (!err) {
self.setIdValue(model, object, id);
object && idName !== '_id' && delete object._id;
}
callback && callback(err, object);

@@ -412,3 +414,3 @@ });

}
callback && callback(err, result.ops);
callback && callback(err, result && result.ops);
});

@@ -468,3 +470,5 @@ };

var spec = false;
var options = null;
if (cond && cond.constructor.name === 'Object') {
options = cond.options;
spec = Object.keys(cond)[0];

@@ -482,5 +486,5 @@ cond = cond[spec];

} else if (spec === 'like') {
query[k] = {$regex: new RegExp(cond)};
query[k] = {$regex: new RegExp(cond, options)};
} else if (spec === 'nlike') {
query[k] = {$not: new RegExp(cond)};
query[k] = {$not: new RegExp(cond, options)};
} else if (spec === 'neq') {

@@ -675,3 +679,3 @@ query[k] = {$ne: cond};

}
var object = result.value;
var object = result && result.value;
if (!err && !object) {

@@ -678,0 +682,0 @@ // No result

{
"name": "loopback-connector-mongodb",
"version": "1.6.0",
"version": "1.7.0",
"description": "LoopBack MongoDB Connector",

@@ -23,6 +23,7 @@ "keywords": [

"devDependencies": {
"loopback-datasource-juggler": "^2.13.0",
"should": "~1.2.2",
"loopback-datasource-juggler": "^2.15.0",
"mocha": "^2.1.0",
"rc": "^0.5.5"
"rc": "^0.5.5",
"semver": "^4.2.0",
"should": "^4.6.3"
},

@@ -29,0 +30,0 @@ "repository": {

@@ -6,3 +6,3 @@ // This test written in mocha+should.js

describe('mongodb', function () {
describe('mongodb connector', function () {

@@ -113,3 +113,3 @@ before(function () {

(!!err).should.be.true;
err.message.should.be.equal('connect ECONNREFUSED');
err.message.should.match(/connect ECONNREFUSED/);
done();

@@ -168,7 +168,7 @@ });

person._id.should.be.equal(3);
PostWithNumberUnderscoreId.findById(person._id, function (err, p) {
should.not.exist(err);
p.content.should.be.equal("test");
done();

@@ -271,3 +271,3 @@ });

post.should.have.property('title', 'a');
post.should.not.have.property('content');
post.should.have.property('content', undefined);
should.not.exist(post._id);

@@ -506,145 +506,155 @@

it('should use $set by default if no operator is supplied', function (done) {
User.create({name: 'Al', age: 31, email:'al@strongloop'}, function (err1, createdusers1) {
should.not.exist(err1);
User.create({name: 'Simon', age: 32, email:'simon@strongloop'}, function (err2, createdusers2) {
should.not.exist(err2);
User.create({name: 'Ray', age: 31, email:'ray@strongloop'}, function (err3, createdusers3) {
should.not.exist(err3);
var describeMongo26 = describe;
if (process.env.MONGODB_VERSION &&
require('semver').satisfies('2.6.0', '>' +
process.env.MONGODB_VERSION)) {
describeMongo26 = describe.skip;
}
User.updateAll({name: 'Simon'}, {name: 'Alex'}, function(err, updatedusers) {
should.not.exist(err);
updatedusers.should.be.equal(1);
describeMongo26('extended operators', function() {
User.find({where: {name: 'Alex'}}, function (err, founduser) {
it('should use $set by default if no operator is supplied', function(done) {
User.create({name: 'Al', age: 31, email: 'al@strongloop'}, function(err1, createdusers1) {
should.not.exist(err1);
User.create({name: 'Simon', age: 32, email: 'simon@strongloop'}, function(err2, createdusers2) {
should.not.exist(err2);
User.create({name: 'Ray', age: 31, email: 'ray@strongloop'}, function(err3, createdusers3) {
should.not.exist(err3);
User.updateAll({name: 'Simon'}, {name: 'Alex'}, function(err, updatedusers) {
should.not.exist(err);
founduser.length.should.be.equal(1);
founduser[0].name.should.be.equal('Alex');
updatedusers.should.be.equal(1);
done();
User.find({where: {name: 'Alex'}}, function(err, founduser) {
should.not.exist(err);
founduser.length.should.be.equal(1);
founduser[0].name.should.be.equal('Alex');
done();
});
});
});
});
});
});
it('should be possible to use the $inc operator', function(done) {
User.dataSource.settings.allowExtendedOperators = true;
User.create({name: 'Al', age: 31, email: 'al@strongloop'}, function(err1, createdusers1) {
should.not.exist(err1);
User.create({name: 'Simon', age: 32, email: 'simon@strongloop'}, function(err2, createdusers2) {
should.not.exist(err2);
User.create({name: 'Ray', age: 31, email: 'ray@strongloop'}, function(err3, createdusers3) {
should.not.exist(err3);
User.updateAll({name: 'Ray'}, {'$inc': {age: 2}}, function(err, updatedusers) {
should.not.exist(err);
updatedusers.should.be.equal(1);
User.find({where: {name: 'Ray'}}, function(err, foundusers) {
should.not.exist(err);
foundusers.length.should.be.equal(1);
foundusers[0].age.should.be.equal(33);
done();
});
})
});
});
});
});
});
it('should be possible to use the $inc operator', function (done) {
User.dataSource.settings.allowExtendedOperators = true;
User.create({name: 'Al', age: 31, email:'al@strongloop'}, function (err1, createdusers1) {
should.not.exist(err1);
User.create({name: 'Simon', age: 32, email:'simon@strongloop'}, function (err2, createdusers2) {
it('should be possible to use the $min and $max operators', function(done) {
User.dataSource.settings.allowExtendedOperators = true;
User.create({name: 'Simon', age: 32, email: 'simon@strongloop'}, function(err2, createdusers2) {
should.not.exist(err2);
User.create({name: 'Ray', age: 31, email:'ray@strongloop'}, function (err3, createdusers3) {
should.not.exist(err3);
User.updateAll({name: 'Ray'}, {'$inc': {age: 2}}, function(err, updatedusers) {
User.updateAll({name: 'Simon'}, {'$max': {age: 33}}, function(err, updatedusers) {
should.not.exist(err);
updatedusers.should.be.equal(1);
User.updateAll({name: 'Simon'}, {'$min': {age: 31}}, function(err, updatedusers) {
should.not.exist(err);
updatedusers.should.be.equal(1);
User.find({where: {name: 'Ray'}}, function (err, foundusers) {
User.find({where: {name: 'Simon'}}, function(err, foundusers) {
should.not.exist(err);
foundusers.length.should.be.equal(1);
foundusers[0].age.should.be.equal(33);
foundusers[0].age.should.be.equal(31);
done();
});
})
});
});
});
});
});
it('should be possible to use the $min and $max operators', function (done) {
User.dataSource.settings.allowExtendedOperators = true;
User.create({name: 'Simon', age: 32, email:'simon@strongloop'}, function (err2, createdusers2) {
should.not.exist(err2);
it('should be possible to use the $mul operator', function(done) {
User.dataSource.settings.allowExtendedOperators = true;
User.create({name: 'Al', age: 31, email: 'al@strongloop'}, function(err1, createdusers1) {
should.not.exist(err1);
User.updateAll({name: 'Simon'}, {'$max': {age: 33}}, function(err, updatedusers) {
should.not.exist(err);
updatedusers.should.be.equal(1);
User.updateAll({name: 'Simon'}, {'$min': {age: 31}}, function(err, updatedusers) {
User.updateAll({name: 'Al'}, {'$mul': {age: 2}}, function(err, updatedusers) {
should.not.exist(err);
updatedusers.should.be.equal(1);
User.find({where: {name: 'Simon'}}, function(err, foundusers) {
User.find({where: {name: 'Al'}}, function(err, foundusers) {
should.not.exist(err);
foundusers.length.should.be.equal(1);
foundusers[0].age.should.be.equal(31);
foundusers[0].age.should.be.equal(62);
done();
});
});
});
});
});
it('should be possible to use the $mul operator', function (done) {
User.dataSource.settings.allowExtendedOperators = true;
User.create({name: 'Al', age: 31, email:'al@strongloop'}, function (err1, createdusers1) {
should.not.exist(err1);
User.updateAll({name: 'Al'}, {'$mul': {age: 2}}, function(err, updatedusers) {
should.not.exist(err);
updatedusers.should.be.equal(1);
User.find({where: {name: 'Al'}}, function(err, foundusers) {
it('should be possible to use the $rename operator', function(done) {
User.dataSource.settings.allowExtendedOperators = true;
User.create({name: 'Al', age: 31, email: 'al@strongloop'}, function(err1, createdusers1) {
should.not.exist(err1);
User.updateAll({name: 'Al'}, {'$rename': {name: 'firstname'}}, function(err, updatedusers) {
should.not.exist(err);
foundusers.length.should.be.equal(1);
foundusers[0].age.should.be.equal(62);
updatedusers.should.be.equal(1);
done();
User.find({where: {firstname: 'Al'}}, function(err, foundusers) {
should.not.exist(err);
foundusers.length.should.be.equal(1);
done();
});
});
});
});
});
it('should be possible to use the $rename operator', function (done) {
User.dataSource.settings.allowExtendedOperators = true;
User.create({name: 'Al', age: 31, email:'al@strongloop'}, function (err1, createdusers1) {
should.not.exist(err1);
User.updateAll({name: 'Al'}, {'$rename': {name: 'firstname'}}, function(err, updatedusers) {
should.not.exist(err);
updatedusers.should.be.equal(1);
it('should be possible to use the $unset operator', function(done) {
User.dataSource.settings.allowExtendedOperators = true;
User.create({name: 'Al', age: 31, email: 'al@strongloop'}, function(err1, createdusers1) {
should.not.exist(err1);
User.find({where: {firstname: 'Al'}}, function(err, foundusers) {
User.updateAll({name: 'Al'}, {'$unset': {email: ''}}, function(err, updatedusers) {
should.not.exist(err);
foundusers.length.should.be.equal(1);
updatedusers.should.be.equal(1);
done();
});
});
});
User.find({where: {name: 'Al'}}, function(err, foundusers) {
should.not.exist(err);
foundusers.length.should.be.equal(1);
should.not.exist(foundusers[0].email);
});
done();
});
it('should be possible to use the $unset operator', function (done) {
User.dataSource.settings.allowExtendedOperators = true;
User.create({name: 'Al', age: 31, email:'al@strongloop'}, function (err1, createdusers1) {
should.not.exist(err1);
User.updateAll({name: 'Al'}, {'$unset': {email: ''}}, function(err, updatedusers) {
should.not.exist(err);
updatedusers.should.be.equal(1);
User.find({where: {name: 'Al'}}, function(err, foundusers) {
should.not.exist(err);
foundusers.length.should.be.equal(1);
should.not.exist(foundusers[0].email);
done();
});
});
});
});

@@ -681,3 +691,3 @@

var newattributes= {$set : {description:'goes well with butter'}, $addToSet : { pricehistory: { '2014-12-12':110 } } };
product.updateAttributes(newattributes, function (err1, inst) {

@@ -688,3 +698,3 @@ should.not.exist(err1);

should.not.exist(err2);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -707,6 +717,6 @@ updatedproduct.name.should.be.equal(product.name);

product.$addToSet = { pricehistory: { '2014-12-12':110 } };
Product.updateOrCreate(product, function (err, updatedproduct) {
should.not.exist(err);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -719,3 +729,3 @@ updatedproduct.name.should.be.equal(product.name);

done();
});

@@ -732,6 +742,6 @@ });

product.$addToSet = { pricehistory: { '2014-10-10':80 } };
Product.updateOrCreate(product, function (err, updatedproduct) {
should.not.exist(err);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -744,6 +754,6 @@ updatedproduct.name.should.be.equal(product.name);

done();
});
});
});
});

@@ -755,3 +765,3 @@ it('updateAttributes: $addToSet should not append item to an Array if it does already exist', function (done) {

var newattributes= {$set : {description:'goes well with butter'}, $addToSet : { pricehistory: { '2014-12-12':110 } } };
product.updateAttributes(newattributes, function (err1, inst) {

@@ -762,3 +772,3 @@ should.not.exist(err1);

should.not.exist(err2);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -773,3 +783,3 @@ updatedproduct.name.should.be.equal(product.name);

});
});
});

@@ -782,3 +792,3 @@

var newattributes= {$set : {description:'goes well with butter'}, $addToSet : { pricehistory: 1 } };
product.updateAttributes(newattributes, function (err1, inst) {

@@ -789,3 +799,3 @@ should.not.exist(err1);

should.not.exist(err2);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -800,3 +810,3 @@ updatedproduct.name.should.be.equal(product.name);

});
});
});

@@ -809,6 +819,6 @@ it('updateOrCreate: $pop should remove first or last item from an Array', function (done) {

product.$pop = { pricehistory: 1 };
Product.updateOrCreate(product, function (err, updatedproduct) {
should.not.exist(err);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -823,3 +833,3 @@ updatedproduct.name.should.be.equal(product.name);

should.not.exist(err);
should.not.exist(p._id);
should.not.exist(p._id);
updatedproduct.pricehistory[0]['2014-10-10'].should.be.equal(80);

@@ -830,3 +840,3 @@ done();

});
});
});

@@ -838,3 +848,3 @@ it('updateAttributes: $pull should remove items from an Array if they match a criteria', function (done) {

var newattributes= {$set : {description:'goes well with butter'}, $pull: { pricehistory: {$gte:90 } } };
product.updateAttributes(newattributes, function (err1, updatedproduct) {

@@ -844,3 +854,3 @@ should.not.exist(err1);

should.not.exist(err1);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -864,6 +874,6 @@ updatedproduct.name.should.be.equal(product.name);

product.$pull = { pricehistory: {$gte:90 }};
Product.updateOrCreate(product, function (err, updatedproduct) {
should.not.exist(err);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -878,3 +888,3 @@ updatedproduct.name.should.be.equal(product.name);

});
});
});

@@ -886,3 +896,3 @@ it('updateAttributes: $pullAll should remove items from an Array if they match a value from a list', function (done) {

var newattributes= {$set : {description:'goes well with butter'}, $pullAll : { pricehistory: [80,100]} };
product.updateAttributes(newattributes, function (err1, inst) {

@@ -893,3 +903,3 @@ should.not.exist(err1);

should.not.exist(err2);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -900,3 +910,3 @@ updatedproduct.name.should.be.equal(product.name);

updatedproduct.pricehistory[1].should.be.equal(90);
done();

@@ -907,3 +917,3 @@ });

});
});
});

@@ -916,6 +926,6 @@ it('updateOrCreate: $pullAll should remove items from an Array if they match a value from a list', function (done) {

product.$pullAll = { pricehistory: [80,100]};
Product.updateOrCreate(product, function (err, updatedproduct) {
should.not.exist(err);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -930,3 +940,3 @@ updatedproduct.name.should.be.equal(product.name);

});
});
});

@@ -937,5 +947,5 @@

Product.create({name: 'bread', price: 100, pricehistory:[{'2014-11-11':90},{ '2014-10-10':80 }]}, function (err, product) {
var newattributes= {$set : {description:'goes well with butter'}, $push : { pricehistory: { '2014-10-10':80 } } };
product.updateAttributes(newattributes, function (err1, inst) {

@@ -946,3 +956,3 @@ should.not.exist(err1);

should.not.exist(err2);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -959,3 +969,3 @@ updatedproduct.name.should.be.equal(product.name);

});
});
});

@@ -968,6 +978,6 @@ it('updateOrCreate: $push should append item to an Array even if it does already exist', function (done) {

product.$push = { pricehistory: { '2014-10-10':80 } };
Product.updateOrCreate(product, function (err, updatedproduct) {
should.not.exist(err);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -981,3 +991,3 @@ updatedproduct.name.should.be.equal(product.name);

done();
});

@@ -995,6 +1005,6 @@ });

product.description = 'alternative description';
Product.updateOrCreate(product, function (err, updatedproduct) {
should.not.exist(err);
should.not.exist(updatedproduct._id);
should.not.exist(updatedproduct._id);
updatedproduct.id.should.be.eql(product.id);

@@ -1010,3 +1020,3 @@ updatedproduct.name.should.be.equal(product.name);

done();
});

@@ -1016,3 +1026,3 @@ });

it('updateOrCreate should update the instance without removing existing properties', function (done) {

@@ -1154,3 +1164,3 @@ Post.create({title: 'a', content: 'AAA', comments: ['Comment1']}, function (err, post) {

post.should.have.property('title', 'b');
post.should.not.have.property('content');
post.should.have.property('content', undefined);
should.not.exist(post._id);

@@ -1224,2 +1234,12 @@ should.not.exist(post.id);

it('should allow to find using case insensitive like', function (done) {
Post.create({title: 'My Post', content: 'Hello'}, function (err, post) {
Post.find({where: {title: {like: 'm.+st', options: 'i'}}}, function (err, posts) {
should.not.exist(err);
posts.should.have.property('length', 1);
done();
});
});
});
it('should support like for no match', function (done) {

@@ -1245,2 +1265,12 @@ Post.create({title: 'My Post', content: 'Hello'}, function (err, post) {

it('should allow to find using case insensitive nlike', function (done) {
Post.create({title: 'My Post', content: 'Hello'}, function (err, post) {
Post.find({where: {title: {nlike: 'm.+st', options: 'i'}}}, function (err, posts) {
should.not.exist(err);
posts.should.have.property('length', 0);
done();
});
});
});
it('should support nlike for no match', function (done) {

@@ -1247,0 +1277,0 @@ Post.create({title: 'My Post', content: 'Hello'}, function (err, post) {

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