Open Rajivkumar1234 opened 5 years ago
There's no field type for something like that. Ideally, it would look like a repeater field type if you're coming from Wordpress.
You can always store the array as a type : Schema.Types.Mixed Eg:
var Schema = mongoose.Schema;
Data.schema.add({
ImageData : {
type : Schema.Types.Mixed
}
});
Keep in mind that it won't render on the admin UI. You can still use it as an array-of-objects field programmatically.
Does this works on the keystone 4 ?
Yep, this is for keystone 4
So a seperate model that would handle the the mixed schema ?
var Schema = mongoose.Schema;
Data.schema.add({
ImageData : {
type : Schema.Types.Mixed
}
});
Data.add({
name: { type: String, required: false },
Type: { type: Types.Select, options: 'New, Used,', index: true },
content: {
brief: { type: Types.Html, wysiwyg: true, height: 150 },
extended: { type: Types.Html, wysiwyg: true, height: 400 },
},
});
So a seperate model that would handle the the mixed schema ?
var Schema = mongoose.Schema; Data.schema.add({ ImageData : { type : Schema.Types.Mixed } });
Data.add({ name: { type: String, required: false }, Type: { type: Types.Select, options: 'New, Used,', index: true }, content: { brief: { type: Types.Html, wysiwyg: true, height: 150 }, extended: { type: Types.Html, wysiwyg: true, height: 400 }, }, });
No, not a seperate schema(you can do that too if it floats your boat) but just a mixed types field. For example:
Data.add({
name: { type: String, required: false },
Type: { type: Types.Select, options: 'New, Used,', index: true },
ImageData : { type : Schema.Types.Mixed },
content: {
brief: { type: Types.Html, wysiwyg: true, height: 150 },
extended: { type: Types.Html, wysiwyg: true, height: 400 },
},
});
That would raise an error throw new Error('Unrecognised field constructor: ' + options.type);****
That would raise an error throw new Error('Unrecognised field constructor: ' + options.type);****
Are you using keystone 4? If you can show me your model file I can try to figure out the problem.
var keystone = require('keystone');
var Types = keystone.Field.Types;
var mongoose = require('mongoose');
/**
Vehicle
=====
*/
var Vehicle = new keystone.List('Vehicle', {
label: 'Vehicle',
});
var Schema = mongoose.Schema;
var vehicleImgStorage = new keystone.Storage({
adapter: keystone.Storage.Adapters.FS,
fs: {
// required; path where the files should be stored
path: keystone.expandPath('server/public/img'),
generateFilename: function (file, index) {
return file.originalname;
},
schema: {
url: true,
},
whenExists: 'error',
// path where files will be served
publicPath: '/public/img',
},
});
Vehicle.add({
name: { type: String, required: false },
Type: { type: Types.Select, options: 'New, Used,', index: true },
Stock: { type: String, required: false },
ImageData : { type : Schema.Types.Mixed },
Comment: { type: String, required: false },
FuelType: { type: String, required: false },
DriveType: { type: String, required: false },
state: { type: Types.Select, options: 'draft, published, archived', default: 'published', index: true },
author: { type: Types.Relationship, initial: true, ref: 'User', index: true },
publishedDate: { type: Types.Date, index: true, dependsOn: { state: 'published' } },
content: {
brief: { type: Types.Html, wysiwyg: true, height: 150 },
extended: { type: Types.Html, wysiwyg: true, height: 400 },
},
});
// Vehicle.schema.add({
// ImageData: {
// type: Schema.Types.Mixed
// },
// TestData:{
// type: Schema.Types.Mixed
// }
// });
Vehicle.schema.post('save', function () {
if (!this.wasNew) return;
if (this.author) {
keystone.list('User').model.findById(this.author).exec(function (err, user) {
if (user) {
user.wasActive().save();
}
});
}
});
Vehicle.track = true;
Vehicle.defaultColumns = 'Type , Model , VIN , Stock ';
Vehicle.register();
I am using Keystone 4
I am using Keystone 4
Try this:
Vehicle.add({
name: { type: String, required: false },
Type: { type: Types.Select, options: "New, Used,", index: true },
Stock: { type: String, required: false },
//ImageData: { type: Schema.Types.Mixed },
Comment: { type: String, required: false },
FuelType: { type: String, required: false },
DriveType: { type: String, required: false },
state: {
type: Types.Select,
options: "draft, published, archived",
default: "published",
index: true
},
author: { type: Types.Relationship, initial: true, ref: "User", index: true },
publishedDate: {
type: Types.Date,
index: true,
dependsOn: { state: "published" }
},
content: {
brief: { type: Types.Html, wysiwyg: true, height: 150 },
extended: { type: Types.Html, wysiwyg: true, height: 400 }
}
});
Vehicle.schema.add({
ImageData: {
type: Schema.Types.Mixed
}
});
@shash7 , does not work either
@shash7 , does not work either
As in, does keystone crash or does the model not show imageData. Cause there won't be a UI for imageData as there's no field available for the mixed data type.
Cause there won't be a UI for imageData as there's no field available for the mixed data type , you are talking about the UI on the admin of keystone right ?
Yep
Yep
Yeah2, I know it wont appear.
Just don't know why it does not seem to work , no error either .
Hi sir , ah , may i ask a question about configuring keystone js plus mongo grid fs? … On Thu, Sep 26, 2019 at 4:42 PM Shashwat amin @.***> wrote: Yep — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#4966?email_source=notifications&email_token=ADSFLSDIYZVDKJGVJMCXVVLQLRYXXA5CNFSM4IWBD5LKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7UZZWQ#issuecomment-535403738>, or mute the thread https://github.com/notifications/unsubscribe-auth/ADSFLSCVANTSQQBKYS57N5TQLRYXXANCNFSM4IWBD5LA .
I don't know much about mongo fs but I highly recommend using cloudinary or s3 as they make it way easier to handle files.
Just don't know why it does not seem to work , no error either .
What do you mean it doesn't work. Give me some specifics.
Data is not being added , checked the mongo db \
Data is not being added , checked the mongo db \
How are you adding the data? Do you have some code you can show?
you can use Types.List (in branch nested-lists-fork
), and I have forked for the master in my github
Any solution for this I need to do the same? @wenchao1020 @shash7 I have an unknown object instead which may vary so can't define a schema for it
I use this to add an object with mixed values:
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var User = new keystone.List("User", {
});
User.add({
// .. add your fields here
});
User.schema.add({
meta: {
type: Schema.Types.Mixed
}
});
Add this after your keystone schema definition. Keep in mind that there will be no admin UI for this.
In my program I generated an array of objects which is the ImageData , Now I want to save that data to mongo Db , I have no problem with other Keys except the ImageData key because I dont know what field type to use to be able to insert those data below which are an array of objects . What field type in keystone we could use to save those array of object example below ?. Thank you.
Model
JSON DATA - Key and value