Getting Error While Creating Text Index in MongoDB - mongodb

db.inventory.createIndex(
{'category.name': 'text',
'brand.name': 'text',
'name': 'text',
'store.name': 'text',
'collection_1' : 'text',
'sku' : 'text',
'parent_sku' : 'text'
})
While Using This Commands getting error like "exception: namespace name generated from index name"
I'm using this because I M creating full Text Index in my application..
I have required many fields for Search index..
Then What should i have to do...????

You usually get this error when the auto generated index name is too long. The index name is generated by concatenating the different column names, however, the length is limited to 125 characters according to the documentation. You can resolve this error by manually specifying a shorter index name when creating the index:
db.inventory.createIndex({
'category.name': 'text',
'brand.name': 'text',
'name': 'text',
'store.name': 'text',
'collection_1': 'text',
'sku': 'text',
'parent_sku': 'text'
},
{
name: "myIndex1"
}
)

Related

How can I sort a views field created in hook_views_data_alter?

In a custom drupal 9 module I define a new field for a view within hook_views_data_alter(&$data).
$data['node']['node_views_mydata'] = array(
'title' => t('Node Views Mydata'),
'field' => array(
'title' => t('Node views mydata'),
'help' => t('Shows some data in views'),
'id' => 'node_views_mydata',
'sort' => [
'node_views_mydata' => 'default',
],
)
);
I have also defined a field plugin processing text data for this field, and can insert and output the field in views.
Now I would like to make the field sortable. But I can't do that. I always get the error "unknown column". In fact, node_views_data is not a "real" node field, but only created on the fly via the hook.
Is there nevertheless a way to sort by this column?

Assert\Expression gives Variable Not Valid around position 2

I have a form. I am trying to assert that if one field is not null, then another field must also not be null. Trying to do this with Symfony annotations as I don't want the code in the controller and was told this would be a good way to do it.
I have tried using an Assert\Expression, however I keep getting various errors on the field that I am checking. It's slightly concerning that it says Variable when I need it to be referring to a field.
// The field that I want to check if it is null
'activeTestData',
null,
[
'label' => 'form.label.active_test_data',
'required' => false,
]
)
->add(
// The field that can't be null if the activeTestData field is not null
'activeTestDataUnit',
ChoiceType::class,
[
'label' => 'form.label.active_test_data_unit',
'required' => false,
'choices' => [
'form.label.active_test_please_select' => '',
'Byte(s)' => 'b',
'Kilobyte(s)' => 'k',
'Megabyte(s)' => 'm',
'Gigabyte(s)' => 'g',
],
// Where I am having the issue
'constraints' => [
new Assert\Expression([
'expression' => "!activeTestData == null",
'message' => 'Please enter a unit for active test data'
]),
],
I want a FORM error for when there is nothing in activeTestDataUnit but there is something in activeTestData. Unfortunately I get a symfony error:
Variable "activeTestData" is not valid around position 2 for expression !activeTestData == null.
Correct syntax for this situation would be the following:
"!this.getParent().get('activeTestData')->getData() == null"
You can see more examples and details on symfony documentation.
I updated my answer. In this context "this" is a Form object of a "activeTestDataUnit" field. So to check for a "activeTestData" value you have go to to the parent and then get a correct child.
As of Symfony 4.1 you can pass your custom values to the "values" argument and avoid all of this clutter, by passing $builder->getData(). See here for the more information on symfony documentation

Laravel form with placeholder, class and input::old

I am trying to get used to work with Laravel's blade.
I would like to create a text input called company.
The input field needs to have an id and a class.
I also want to show a placeholder if there is no data in the database, or the data stored if already exists.
Finally, I would like to keep the introduced input in case of errors.
I would like to use something similar at this:
{{ Form::text(
'company',
isset($user->company)?$user->company:array('placeholder'=>'Your company'),
array('class' => 'field required', 'id' => 'company'),
Input::old('company')
) }}
Any help would be appreciated. Thanks!
The easy way, using form model binding:
{{ Form::model($user, [ ...options...]) }}
{{ Form::text(
'company', // refers to $user->company
null, // auto populated with old input in case of error OR $user->company
array('class' => 'field required', 'id' => 'company',
'placeholder' => 'Your company') // placeholder is html attribute, don't use model data here
) }}
And if you don't want form model binding, this is all you need:
{{ Form::text(
'company',
$user->company, // auto populated with old input in case of error
array('class' => 'field required', 'id' => 'company',
'placeholder' => 'Your company')
) }}
Laravel will handle re-populating inputs for you, so long as the key in the POST data is the same as your input’s name attribute.
With Form::text(), the first parameter is the field name, the second parameter is the default value you want, and the third parameter is an array of HTML attributes you want set. So, you would have:
{{ Form::text('company', null, array(
'class' => '',
'id' => '',
'placeholder' => '',
)) }}
Obviously replaced the class, id, and placeholder values with your desired values.
Found it!
It works fine for me if I do this:
{{ Form::text(
'company',
Input::old( 'company', $user -> company ) ,
array( 'class' => 'field required', 'id' => 'company', 'placeholder' => 'Your company' )
) }}

symfony2 form field label as an array

I'd like to have 3 separate texts for each field in my form as a label. They are separate, because they need to be styled differently. I tried this:
$builder->add('total_sales', 'text', array(
'label' => array('num' => '1', 'descr' => 'Total sales', 'category' => 'A'),
'required' => false,
'attr' => array(
'class' => 'field numeric_field',
'maxlength' => 10,
)));
Obviously the above don't work; it will display 'Array' in place of label.
How can I achieve desired effect?
first you'll need to create a custom form type that extends the text type, the reason for this is so you don't mess up other text types you might have elsewhere. After doing that you'll need to style it using a form_div_layout. you can see the details here:
http://symfony.com/doc/current/cookbook/form/form_customization.html

how to change silex form factory name attribute

How do i change the default name attribute for an input in my form that is created using the form factory?
here is an example of the simple form i am using:
$form = $app['form.factory']->createBuilder('form')
->add('image','file)
->add('longitude', 'hidden')
->add('latitude', 'hidden')
->getForm();
i have tried putting the attributes into an array without successfully changing the name, although with this method i could change the label or class etc:
->add('latitude', 'text', array('attr'=>array("name"=>'newname')))
it seems like a very simple request to be able to change the name of an input, so you would have thought there would be an obvious way to do it. With the code above it would still show the name as name=form[latitude]
Use createNamedBuilder instead createBuilder to overwrite the fields name. The name will be the first argument in add function.
$personal_form = $app['form.factory']->createNamedBuilder(null, 'form')
->add('name', 'text', array(
'label' => 'Nombre',
'data' => 'Nombre'
))
->add('surname', 'text', array(
'label' => 'Apellidos',
'data' => 'Apellidos'
))
->add('email', 'email', array(
'label' => 'E-mail',
'data' => 'E-mail'
))
->getForm();