Skip to content

Commit

Permalink
Simplify mongodb removeUnsupportedChars
Browse files Browse the repository at this point in the history
  • Loading branch information
leodutra committed Mar 19, 2017
1 parent fa0c0d6 commit 717ba66
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/mongodb-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ MongoDBBackend.prototype = {
var searchParams = (this.useSingle? {_bucketname: bucket, key:key} : {key:key});
var collName = (this.useSingle? aclCollectionName : bucket);

this.db.collection(this.prefix + removeUnsupportedChar(collName, this.useRawCollectionNames),function(err,collection){
this.db.collection(this.prefix + this.removeUnsupportedChar(collName),function(err,collection){
if(err instanceof Error) return cb(err);
// Excluding bucket field from search result
collection.findOne(searchParams, {_bucketname: 0},function(err, doc){
Expand All @@ -85,7 +85,7 @@ MongoDBBackend.prototype = {
var searchParams = (this.useSingle? {_bucketname: bucket, key: { $in: keys }} : {key: { $in: keys }});
var collName = (this.useSingle? aclCollectionName : bucket);

this.db.collection(this.prefix + removeUnsupportedChar(collName, this.useRawCollectionNames),function(err,collection){
this.db.collection(this.prefix + this.removeUnsupportedChar(collName),function(err,collection){
if(err instanceof Error) return cb(err);
// Excluding bucket field from search result
collection.find(searchParams, {_bucketname: 0}).toArray(function(err,docs){
Expand Down Expand Up @@ -117,7 +117,7 @@ MongoDBBackend.prototype = {
var collName = (self.useSingle? aclCollectionName : bucket);
transaction.push(function(cb){
values = makeArray(values);
self.db.collection(self.prefix + removeUnsupportedChar(collName, self.useRawCollectionNames), function(err,collection){
self.db.collection(self.prefix + self.removeUnsupportedChar(collName), function(err,collection){
if(err instanceof Error) return cb(err);

// build doc from array values
Expand All @@ -133,7 +133,7 @@ MongoDBBackend.prototype = {
});

transaction.push(function(cb) {
self.db.collection(self.prefix + removeUnsupportedChar(collName, self.useRawCollectionNames), function(err,collection){
self.db.collection(self.prefix + self.removeUnsupportedChar(collName), function(err,collection){
// Create index
collection.ensureIndex({_bucketname: 1, key: 1}, function(err){
if (err instanceof Error) {
Expand All @@ -159,7 +159,7 @@ MongoDBBackend.prototype = {
var collName = (self.useSingle? aclCollectionName : bucket);

transaction.push(function(cb){
self.db.collection(self.prefix + removeUnsupportedChar(collName, self.useRawCollectionNames),function(err,collection){
self.db.collection(self.prefix + self.removeUnsupportedChar(collName),function(err,collection){
if(err instanceof Error) return cb(err);
collection.remove(updateParams,{safe:true},function(err){
if(err instanceof Error) return cb(err);
Expand All @@ -183,7 +183,7 @@ MongoDBBackend.prototype = {

values = makeArray(values);
transaction.push(function(cb){
self.db.collection(self.prefix + removeUnsupportedChar(collName, self.useRawCollectionNames),function(err,collection){
self.db.collection(self.prefix + self.removeUnsupportedChar(collName),function(err,collection){
if(err instanceof Error) return cb(err);

// build doc from array values
Expand All @@ -197,15 +197,15 @@ MongoDBBackend.prototype = {
});
});
});
}
}
},

function removeUnsupportedChar(text, useRawCollectionNames) {
if (!useRawCollectionNames && (typeof text === 'string' || text instanceof String)) {
text = decodeURIComponent(text);
text = text.replace(/[/\s]/g, '_'); // replaces slashes and spaces
removeUnsupportedChar: function(text) {
if (!this.useRawCollectionNames && (typeof text === 'string' || text instanceof String)) {
text = decodeURIComponent(text);
text = text.replace(/[/\s]/g, '_'); // replaces slashes and spaces
}
return text;
}
return text;
}

function encodeText(text) {
Expand Down

0 comments on commit 717ba66

Please sign in to comment.