How to create indexes in mongoDB using code? - mongodb

I searched this in the Internet and found db.collectionName.createIndex() method. But in this way the index must be set in terminal if local database or using some UI in Mongo Atlas.But when we share our code index won't be created at their end for their table.Is there any way to create an index using code like we do in sql while declaring a primary key.

Related

Talend Open Studio : creating table in MySQL dynamically

I am trying to find out how to do dynamic creation of tables in MySQL using Talend.
In other ETL tools such as Pentaho they have a specific component called "metadata" to do this.
So my use case is the following:
1) Create database manually in MySQL
2) Use Talend to read CSV Header info, and use this as the fields of a table to be created in MySQL using Talend.
I have searched and could not find anything for this specific feature online.
[Note : using Talend Open Studio for Big Data Version: 6.4.1]
UPDATE:
I have made progress on this, but running into issues trying to generate a primary key on the MySQL output using the NumericSequence function.
My data does not have natively a primary key, but wish to include one:
I have a screenshot of the tMap attached here:
Also I am getting a compile/build error. It seems it does not like the primary key generation it seems.
See attached image.
And here also is the tMySQLOutput settings for Primary Key:
More Work Done:
I have changed the name of the Primary Key in the tMySQL component to match the name of the tMap output area component, i get the same compile error.
I will attach this error here:
To create dynamically MySQL tables in Talend, you can use one of the "Action on table" options in tMysqlOutput components (in your case, "Create table...").
https://help.talend.com/reader/4I8tDQGtrOPDl5MXAS3Q~w/aDNKleHXlevILu9pnbCoNg
Don't forget to define correctly PK fields for further inserts, updates, deletes...
Then, if necessary, through your favorite Database Tool (MySQL Workbench, DBeaver or other), you can retrieve the DDL (and DML) script(s).
I hope this answers to your problem/question.

trying to delete data from table

in mysql workbench im trying to execute
delete from basic_info where rollno>3;
this query but im getting this message
Error Code: 1175. You are using safe update mode and you tried to
update a table without a WHERE that uses a KEY column To disable safe
mode, toggle the option in Preferences -> SQL Editor and reconnect.
You can try using below commands.
SET SQL_SAFE_UPDATES=0;
delete from basic_info where rollno>3;
SET SQL_SAFE_UPDATES=1;
Create an INDEX with rollno column, good for a long term not only this query
You didn't say which MySQL Workbench you are using, but make sure you always use the latest one to get all latest bugfixes.
Since you obvioulsy have a where clause in your query it looks like it is not recognized (which would be a bug). Hence my advice to use the latest version.
In any case you can disable the safety check in the preferences of MySQL Workbench.

Disable & enable of Index in db2luw

is it possible to temporarily disable & again enable of an index on a table in db2luw.
If so can some one tell me the syntax or process, to achieve this.
I am updating tons of records . Before that I have to disable all the indexes on all the tables & after that have to create only one user created index (I9) on all the tables. My update query has to be run only with one index(I9).
When once my update query got completed. again I have to reset all the tables to their original position(previous indexes).
I am very new to db2. kindly excuse me if I am wrong at any stage in my question.
That is what I am trying to find.
If you have a better solution for this, can you please let me know.It l be a very good favour.
Thanks
You can't "disable" an index. Please see DROP INDEX <name> and CREATE INDEX <name>.

Using SQLite Manager to create indexes

I've created and index named "setIndex" for table "mySets" on column "setID" with the SQLite Manager (firefox). In order for the app to use them in a query, do I have to specify anything like the index name when searching my table?
SELECT * FROM mySets WHERE setID='setMatrix'
No, you don't have anything more to do; you can't explicitly make SQLite use an index when running a query. The database engine (SQLite but that goes for all the others) will decide whether to use your index if it's there and if it considers it appropriate to do so.

JPA model update [1.1.1]

I'm sure this is something very simple, but for the life of me can't
find the correct keywords on google.
Basically I've updated a couple models since my last deployment. Dev is set up with the jpa.ddl default setting of create-drop. Now I read that prod isn't supposed to run with jpa.ddl=update, so does that mean I have to manually script a schema change? I couldn't find any documentation saying the correct way. I am also using playapps, so the database is set up there. I set up ssl, so I should have sql access via command line. However, I was having difficulty figuring out the syntax for modifying the db. I'm so used to a gui environment such as phpMySQL or microsoft's sql server. The errors specifically I'm getting are the following two (when running the application after uploading to prod).
Unsuccessful: alter table PhotoSlide add index FK57E3FABF5C905145 (aPhoto_id), add constraint FK57E3FABF5C905145 foreign key (aPhoto_id) references StorePhoto (id)
Cannot add or update a child row: a foreign key constraint fails (play/#sql-2e29_32, CONSTRAINT FK57E3FABF5C905145 FOREIGN KEY (aPhoto_id) REFERENCES StorePhoto (id))
you can achieve that by using the migration module.More details you can find #
http://www.playframework.org/modules/migrate
The flow will be like the below:
You push new code to prod --> you run migrations --> restart the server
More documentation at :
https://github.com/dcardon/play-migrate/blob/master/documentation/manual/home.textile
With the latest version play supports migrations :
http://www.playframework.org/documentation/1.2.4/evolutions