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

sails-mongo

Package Overview
Dependencies
Maintainers
4
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sails-mongo - npm Package Compare versions

Comparing version 0.10.0-rc3 to 0.10.0-rc4

.travis.yml

23

lib/adapter.js

@@ -338,2 +338,25 @@ /*---------------------------------------------------------------

/**
* Count
*
* Return a count of the number of records matching a criteria.
*
* @param {String} connectionName
* @param {String} collectionName
* @param {Object} options
* @param {Function} callback
*/
count: function(connectionName, collectionName, options, cb) {
var connectionObject = connections[connectionName];
var collection = connectionObject.collections[collectionName];
// Find matching documents and return the count
collection.count(options, function(err, results) {
if(err) return cb(err);
cb(null, results);
});
},
identity: 'sails-mongo'

@@ -340,0 +363,0 @@ };

41

lib/collection.js

@@ -123,3 +123,3 @@

if(err) return cb(err);
cb(null, utils.rewriteIds(results));
cb(null, utils.rewriteIds(results, self.schema));
});

@@ -177,3 +177,3 @@ };

if(err) return cb(err);
cb(null, utils.rewriteIds(records));
cb(null, utils.rewriteIds(records, self.schema));
});

@@ -221,7 +221,33 @@ });

cb(null, utils.rewriteIds(resultArray));
cb(null, utils.rewriteIds(resultArray, self.schema));
});
};
/**
* Count Documents
*
* @param {Object} criteria
* @param {Function} callback
* @api public
*/
Collection.prototype.count = function count(criteria, cb) {
var self = this;
var query;
// Catch errors build query and return to the callback
try {
query = new Query(criteria);
} catch(err) {
return cb(err);
}
this.connection.db.collection(this.identity).count(query.criteria.where, function(err, count) {
if (err) return cb(err);
cb(null, count);
});
};
/////////////////////////////////////////////////////////////////////////////////

@@ -267,5 +293,10 @@ // PRIVATE METHODS

Object.keys(this.schema).forEach(function(key) {
var index = {},
options = {};
var index = {};
var options = {};
// If index key is `id` ignore it because Mongo will automatically handle this
if(key === 'id') {
return;
}
// Handle Unique Indexes

@@ -272,0 +303,0 @@ if(self.schema[key].unique) {

@@ -34,5 +34,5 @@

options = this.parseTypes(options);
// Normalize Criteria
this.criteria = this.normalizeCriteria(options);
// console.log("Q", require('util').inspect(options, false, null));

@@ -117,2 +117,7 @@ return this;

// if value appears to be a mongo id normalize it as such
if(_.isString(val) && utils.matchMongoId(val)) {
obj[key] = ObjectId(val);
}
// Normalize `or` key into mongo $or

@@ -165,3 +170,3 @@ if(key === 'or') {

var self = this;
// console.log("C", require('util').inspect(options, false, null));
Object.keys(options).forEach(function(key) {

@@ -208,2 +213,20 @@ var original = _.cloneDeep(options[key]);

}
if(Array.isArray(obj)) {
obj.forEach(function(arrayVal, i) {
if(_.isString(arrayVal) && utils.matchMongoId(arrayVal)) {
obj[i] = ObjectId(arrayVal);
}
});
original[key] = { '$in': obj };
// Normalize id, if used, into _id
if(key === 'id') {
var data = _.cloneDeep(original[key]);
delete original[key];
original['_id'] = data;
}
}
return;

@@ -262,7 +285,2 @@ }

// Check for Mongo IDs
if(utils.matchMongoId(obj[attr])) {
return;
}
// Handle Sorting Order with binary or -1/1 values

@@ -396,2 +414,7 @@ if(key === 'sort') {

// Check for Mongo IDs
if(utils.matchMongoId(obj[attr])) {
return;
}
// Ignore special attributes

@@ -398,0 +421,0 @@ if(['_bsontype', '_id', 'id'].indexOf(attr) >= 0) return;

4

package.json
{
"name": "sails-mongo",
"version": "0.10.0-rc3",
"version": "0.10.0-rc4",
"description": "Mongo DB adapter for Sails.js",

@@ -42,3 +42,3 @@ "main": "./lib/adapter.js",

"lodash": "~2.4.1",
"mongodb": "~1.3.23",
"mongodb": "1.4.2",
"waterline-errors": "~0.10.0"

@@ -45,0 +45,0 @@ },

@@ -72,2 +72,4 @@ ![image_squidhome@2x.png](http://i.imgur.com/RIvu9.png)

Don't forget that Mongo uses the ObjectId type for ids.
## Sails.js

@@ -74,0 +76,0 @@

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