@payloadcms/db-mongodb
Advanced tools
Comparing version 3.0.0-canary.fb81f02 to 3.0.0-canary.ff8c8fd
@@ -72,2 +72,3 @@ import fs from 'fs'; | ||
migrationDir, | ||
packageName: '@payloadcms/db-mongodb', | ||
payload, | ||
@@ -74,0 +75,0 @@ prodMigrations, |
@@ -14,2 +14,11 @@ import paginate from 'mongoose-paginate-v2'; | ||
}); | ||
if (Array.isArray(collection.upload.filenameCompoundIndex)) { | ||
const indexDefinition = collection.upload.filenameCompoundIndex.reduce((acc, index)=>{ | ||
acc[index] = 1; | ||
return acc; | ||
}, {}); | ||
schema.index(indexDefinition, { | ||
unique: true | ||
}); | ||
} | ||
if (config.indexSortableFields && collection.timestamps !== false) { | ||
@@ -16,0 +25,0 @@ schema.index({ |
@@ -419,9 +419,80 @@ import mongoose from 'mongoose'; | ||
upload: (field, schema, config, buildSchemaOptions)=>{ | ||
const baseSchema = { | ||
...formatBaseSchema(field, buildSchemaOptions), | ||
type: mongoose.Schema.Types.Mixed, | ||
ref: field.relationTo | ||
}; | ||
const hasManyRelations = Array.isArray(field.relationTo); | ||
let schemaToReturn = {}; | ||
if (field.localized && config.localization) { | ||
schemaToReturn = { | ||
type: config.localization.localeCodes.reduce((locales, locale)=>{ | ||
let localeSchema = {}; | ||
if (hasManyRelations) { | ||
localeSchema = { | ||
...formatBaseSchema(field, buildSchemaOptions), | ||
_id: false, | ||
type: mongoose.Schema.Types.Mixed, | ||
relationTo: { | ||
type: String, | ||
enum: field.relationTo | ||
}, | ||
value: { | ||
type: mongoose.Schema.Types.Mixed, | ||
refPath: `${field.name}.${locale}.relationTo` | ||
} | ||
}; | ||
} else { | ||
localeSchema = { | ||
...formatBaseSchema(field, buildSchemaOptions), | ||
type: mongoose.Schema.Types.Mixed, | ||
ref: field.relationTo | ||
}; | ||
} | ||
return { | ||
...locales, | ||
[locale]: field.hasMany ? { | ||
type: [ | ||
localeSchema | ||
], | ||
default: formatDefaultValue(field) | ||
} : localeSchema | ||
}; | ||
}, {}), | ||
localized: true | ||
}; | ||
} else if (hasManyRelations) { | ||
schemaToReturn = { | ||
...formatBaseSchema(field, buildSchemaOptions), | ||
_id: false, | ||
type: mongoose.Schema.Types.Mixed, | ||
relationTo: { | ||
type: String, | ||
enum: field.relationTo | ||
}, | ||
value: { | ||
type: mongoose.Schema.Types.Mixed, | ||
refPath: `${field.name}.relationTo` | ||
} | ||
}; | ||
if (field.hasMany) { | ||
schemaToReturn = { | ||
type: [ | ||
schemaToReturn | ||
], | ||
default: formatDefaultValue(field) | ||
}; | ||
} | ||
} else { | ||
schemaToReturn = { | ||
...formatBaseSchema(field, buildSchemaOptions), | ||
type: mongoose.Schema.Types.Mixed, | ||
ref: field.relationTo | ||
}; | ||
if (field.hasMany) { | ||
schemaToReturn = { | ||
type: [ | ||
schemaToReturn | ||
], | ||
default: formatDefaultValue(field) | ||
}; | ||
} | ||
} | ||
schema.add({ | ||
[field.name]: localizeSchema(field, baseSchema, config.localization) | ||
[field.name]: schemaToReturn | ||
}); | ||
@@ -428,0 +499,0 @@ } |
{ | ||
"name": "@payloadcms/db-mongodb", | ||
"version": "3.0.0-canary.fb81f02", | ||
"version": "3.0.0-canary.ff8c8fd", | ||
"description": "The officially supported MongoDB database adapter for Payload", | ||
@@ -41,6 +41,6 @@ "homepage": "https://payloadcms.com", | ||
"@payloadcms/eslint-config": "3.0.0-beta.59", | ||
"payload": "3.0.0-canary.fb81f02" | ||
"payload": "3.0.0-canary.ff8c8fd" | ||
}, | ||
"peerDependencies": { | ||
"payload": "3.0.0-canary.fb81f02" | ||
"payload": "3.0.0-canary.ff8c8fd" | ||
}, | ||
@@ -47,0 +47,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
313785
3050